تحسين استخدام الذاكرة أثناء العمل مع الملفات الكبيرة التي تحتوي على مجموعات بيانات كبيرة
عند إنشاء مصنف بمجموعات بيانات كبيرة ، أو قراءة ملف إكسل Microsoft كبير ، فإن الحجم الإجمالي لذاكرة الوصول العشوائي التي ستستغرقها العملية دائمًا ما يكون مصدر قلق. هناك تدابير يمكن تكييفها لمواجهة التحدي. يوفر Aspose.Cells بعض الخيارات ذات الصلة ومكالمات API لخفض وتقليل وتحسين استخدام الذاكرة. أيضًا ، يمكن أن يساعد العملية على العمل بكفاءة أكبر وتشغيل أسرع.
استخدم الMemorySetting.MemoryPreferenceخيار لتحسين استخدام الذاكرة لبيانات الخلايا وتقليل التكلفة الإجمالية للذاكرة. عند إنشاء مجموعة بيانات كبيرة للخلايا ، يمكنها توفير قدر معين من الذاكرة مقارنة باستخدام الإعداد الافتراضي (إعداد الذاكرة).
تحسين الذاكرة
قراءة ملفات إكسل الكبيرة
يوضح المثال التالي كيفية قراءة ملف Excel كبير Microsoft في الوضع الأمثل.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specify the LoadOptions | |
LoadOptions opt = new LoadOptions(); | |
// Set the memory preferences | |
opt.MemorySetting = MemorySetting.MemoryPreference; | |
// Instantiate the Workbook | |
// Load the Big Excel file having large Data set in it | |
Workbook wb = new Workbook(dataDir+ "Book1.xlsx", opt); |
كتابة ملفات إكسل كبيرة
يوضح المثال التالي كيفية كتابة مجموعة بيانات كبيرة إلى ورقة عمل في وضع محسن.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiate a new Workbook | |
Workbook wb = new Workbook(); | |
// Set the memory preferences | |
// Note: This setting cannot take effect for the existing worksheets that are created before using the below line of code | |
wb.Settings.MemorySetting = MemorySetting.MemoryPreference; | |
// Note: The memory settings also would not work for the default sheet i.e., "Sheet1" etc. automatically created by the Workbook | |
// To change the memory setting of existing sheets, please change memory setting for them manually: | |
Cells cells = wb.Worksheets[0].Cells; | |
cells.MemorySetting = MemorySetting.MemoryPreference; | |
// Input large dataset into the cells of the worksheet. | |
// Your code goes here. | |
// ......... | |
// Get cells of the newly created Worksheet "Sheet2" whose memory setting is same with the one defined in WorkbookSettings: | |
cells = wb.Worksheets.Add("Sheet2").Cells; | |
// ......... | |
// Input large dataset into the cells of the worksheet. | |
// Your code goes here. | |
// ......... |
الحذر
الخيار الافتراضي ،إعداد الذاكرةيتم تطبيقه على جميع الإصدارات. بالنسبة لبعض المواقف ، مثل إنشاء مصنف بمجموعة بيانات كبيرة للخلايا ، فإن ملفMemorySetting.MemoryPreferenceالخيار قد يحسن استخدام الذاكرة ويقلل من تكلفة الذاكرة للتطبيق. ومع ذلك ، قد يؤدي هذا الخيار إلى تدهور الأداء في بعض الحالات الخاصة مثل المتابعة.
- يتم الدخول على Cells بشكل عشوائي ومتكرر : التسلسل الأكثر فاعلية للوصول إلى مجموعة الخلايا هو خلية بخلية في صف واحد ، ثم صفًا بصف. على وجه الخصوص ، إذا قمت بالوصول إلى الصفوف / الخلايا التي تم الحصول عليها من EnumeratorCells, مجموعة RowCollection وصف ، سيتم تعظيم الأداء معMemorySetting.MemoryPreference.
- إدراج وحذف Cells الصفوف : يرجى ملاحظة أنه إذا كان هناك الكثير من عمليات الإدراج / الحذف لـ Cells / Rows ، فسيكون تدهور الأداء ملحوظًا فيالذاكرة التفضيل الوضع بالمقارنة معطبيعيالوضع.
- تعمل بأنواع Cell مختلفة : إذا كانت معظم الخلايا تحتوي على قيم سلسلة أو صيغ ، فستكون تكلفة الذاكرة هي نفسهاطبيعي الوضع ولكن إذا كان هناك عدد كبير من الخلايا الفارغة ، أو إذا كانت قيم الخلايا رقمية أو منطقية وما إلى ذلك ، فإن ملفMemorySetting.MemoryPreferenceسيعطي الخيار أداء أفضل.