Büyük Veri Setlerine Sahip Büyük Dosyalarla Çalışırken Bellek Kullanımını Optimize Etme

Bellek Kullanımını Optimize Etme

Büyük Excel Dosyaları Okuma

Aşağıdaki örnek, optimize edilmiş modda büyük bir Microsoft Excel dosyasını nasıl okuyacağınızı göstermektedir.

// 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);

Büyük Excel Dosyaları Yazma

Aşağıdaki örnek, optimize edilmiş bir modda bir çalışma sayfasına büyük bir veri seti yazmanın nasıl yapılacağını gösterir.

// 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.
// .........

Dikkat

Varsayılan seçenek, MemorySetting.Normal tüm sürümler için uygulanır. Ancak, bazı durumlarda, örneğin bir çalışma kitabı oluştururken hücreler için büyük bir veri kümesi oluşturmaları gereken durumlarda, MemorySetting.MemoryPreference seçeneği hafıza kullanımını optimize edebilir ve uygulama için hafıza maliyetini azaltabilir. Bununla birlikte, bu seçenek bazı özel durumlarda performansı düşürebilir.

  1. Rastgele ve Tekrarlanan Şekilde Hücrelere Erişme: Hücre koleksiyonuna erişmek için en verimli sıralama, önce bir satırda hücre hücre, ardından satır satır erişmektir. Özellikle, Cells, RowCollection ve Row‘den elde edilen Numaralayıcı ile satırlara/hücrelere erişiyorsanız, performans MemorySetting.MemoryPreference ile maksimize edilecektir.
  2. Hücreleri ve Satırları Ekleme ve Silme: Hücreler/Satırlar için çok sayıda ekleme/silme işlemi varsa, MemoryPreference modu, Normal moduna göre performansın gözle görülür derecede düşmesine neden olacaktır.
  3. Farklı Hücre Türlerinde Çalışma: Eğer hücrelerin çoğu dize değerleri veya formülleri içeriyorsa, hafıza maliyeti Normal mod ile aynı olacaktır, ancak boş hücreler veya hücre değerleri sayısal, mantıksal vb. ise, MemorySetting.MemoryPreference seçeneği daha iyi performans sunacaktır.