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.

from aspose.cells import LoadOptions, MemorySetting, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Specify the LoadOptions
opt = LoadOptions()
# Set the memory preferences
opt.memory_setting = MemorySetting.MEMORY_PREFERENCE
# Instantiate the Workbook
# Load the Big Excel file having large Data set in it
wb = 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.

from aspose.cells import MemorySetting, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate a new Workbook
wb = 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.memory_setting = MemorySetting.MEMORY_PREFERENCE
# 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 = wb.worksheets[0].cells
cells.memory_setting = MemorySetting.MEMORY_PREFERENCE
# 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

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.MEMORY_PREFERENCE 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.MEMORY_PREFERENCE 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.MEMORY_PREFERENCE seçeneği daha iyi performans sunacaktır.