cart: empty [ Login ]

OutOfMemoryException on DxfWriter.WriteDxf with 30000 blocks

1 
slawekm
2/12/2007 5:53 PM
Hi. When I'm writing about 30k DxfBlock(DxfPolyline with 4 vertex)+DxfInsert with two attributes on every instances - I receive OutOfMemoryException(in both text and binary modes). Virtual memory when filled DxfModel before call DxfWriter.WriteDxf is about 950MB and fast rising up to 1600MB (private 250MB rising to 330MB on building DxfModel and to 890MB on DxfWriter.WriteDxf) . As result is created empty file (binary with single line ?AutoCAD Binary DXF?). Please optimize memory usage on write. As target I need to write much more elements and more complex blocks. Regards Sławomir Marciniak
Wout
2/12/2007 6:10 PM
Hi, I can imagine that strains things! I'll do some testing with this amount of blocks, if you can provide me some test code that would be helpful. Thanks, Wout
slawekm
2/12/2007 7:02 PM
Hi Our application is to complicated and at begin is using 1GB virtual memory so for save to DXF is only 600MB. I not successfully detected minimum amount of blocks that fail in this sample but I think that sample is enought to detect memory problem. private static void WriteTestOutOfMemory(int blocks) { Console.WriteLine('Begin write {0} blocks - {1} MB', blocks, GC.GetTotalMemory(true) / 1048576); DxfModel model = new DxfModel(DxfVersion.Dxf15); for (int i = 0; i < blocks; i++) { DxfBlock block = new DxfBlock(model); block.Name = 'block' + i.ToString(); DxfPolyline2D poly = new DxfPolyline2D(new DxfVertex2D[] { new DxfVertex2D(0, 0), new DxfVertex2D(0, 1), new DxfVertex2D(1, 1), new DxfVertex2D(1, 0) }); block.Entities.Add(poly); model.Blocks.Add(block); DxfInsert insert = new DxfInsert(block, new Point3D(i, 0, 0)); DxfAttribute attr = new DxfAttribute(model, String.Format('//0/.{0}',i), insert.InsertionPoint,0.1); attr.TagString = 'SYSNAME'; attr.Visible = false; insert.Attributes.Add(attr); attr = new DxfAttribute(model, 'Entity number '+i.ToString(), insert.InsertionPoint, 0.1); attr.TagString = 'COMMONNAME'; insert.Attributes.Add(attr); model.Entities.Add(insert); } Console.WriteLine('Filled DxfModel {0} MB', GC.GetTotalMemory(true) / 1048576); DxfWriter.WriteDxf('DxfWriteTestOutOfMemory-bin.dxf', model, true); Console.WriteLine('Saved binary DxfModel {0} MB (Approximation of .NET Memory - No Garbage Collected)', GC.GetTotalMemory(false) / 1048576); Console.ReadLine(); } public static void Main(string[] args) { int blocks = 80000; try { WriteTestOutOfMemory(blocks); } catch (Exception e) { Console.Error.WriteLine('Error occurred: {0} at {1}' + e.Message, blocks); Environment.Exit(1); } }
Wout
2/13/2007 6:10 AM
Sławomir, This problem is due to the way of the bounding box calculation, just before writing the model. The bounding box calculation is changed in the coming release though (consumes far less memory). It still takes a fair amount of time for 30000 blocks, but it does write the file (around 108 Mb). You'll have to wait 1 or 2 weeks for the next release to be finished. Maybe I'll be able to get you a preview release as soon as my obfuscator provider fixes a blocking problem. Wout
slawekm
2/13/2007 12:08 PM
Hi Thanks for the support I can wait 2 weeks for update however I willingly test preview release. Speed of write was another problem but much less urgent than fail on write. I think that should be much faster due to less memory allocation. Thanks again Sławomir Marciniak
Wout
2/16/2007 6:47 AM
Hi Sławomir, Checkout the preview release if you already want to test the next release (see the announcements). There'll be a few breaking changes, so just read the readme.html file or ask questions if you run into problems. Wout
1