カスタム実装のMemory Streamを作成するためのCustomImplementationFactoryを使用する
Contents
[
Hide
]
可能な使用シナリオ
Aspose.Cellsは、デフォルトのMemoryStreamの代わりにRecyclable memory実装などのカスタム実装を提供する CellsHelper.CustomImplementationFactory というAPIを提供しています。
CustomImplementationFactoryを使用してMemory Streamのカスタム実装を作成する
次のサンプルコードは、プログラムでCellsHelper.CustomImplementationFactoryを使用する方法を示しています。システムに十分なメモリがある場合でも、そのメモリが連続していないことがあります。Memory Streamオブジェクトは連続したメモリを使用しますが、非連続のメモリを使用するようにMemory Streamの実装を提供することも可能です。
サンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Implement CustomImplementationFactory - CELLSNET-45461 | |
public class MM : CustomImplementationFactory | |
{ | |
RecyclableMemoryStreamManager manager = new RecyclableMemoryStreamManager(); | |
public override MemoryStream CreateMemoryStream() | |
{ | |
return manager.GetStream("MM"); | |
} | |
public override MemoryStream CreateMemoryStream(int capacity) | |
{ | |
return manager.GetStream("MM", capacity); | |
} | |
} | |
//---------------------------------------- | |
//---------------------------------------- | |
//Assign implementation instance of CustomImplementationFactory | |
CellsHelper.CustomImplementationFactory = new MM(); | |
//Light cells data handler implementation | |
LightCellsDataHandlerVisitCells v = new LightCellsDataHandlerVisitCells(); | |
//Create workbook object | |
Workbook wb = new Workbook(sourceDir, new LoadOptions() { MemorySetting = MemorySetting.MemoryPreference, LightCellsDataHandler = v }); | |
//Print miscellaneous data | |
Console.WriteLine("Total sheets: " + wb.Worksheets.Count + ", cells: " + v.CellCount + ", strings: " + v.StringCount + ", formulas: " + v.FormulaCount); |