Using CustomImplementationFactory to create custom implementation of Memory Stream
Possible Usage Scenarios
Aspose.Cells has provided an API named CellsHelper.CustomImplementationFactory which enables the user to provide custom implementation such as using Recyclable memory implementation instead of the default MemoryStream.
Using CustomImplementationFactory to create custom implementation of Memory Stream
The following sample code illustrates how to make use of CellsHelper.CustomImplementationFactory in your program. Sometimes, there is enough memory in your system but the memory is not contiguous. Memory Stream objects use contiguous memory but you can provide the implementation of Memory Stream in such a way that it uses the non-contiguous memory instead,
Sample Code
// 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); |