How to preallocate objects in C++ instead of using new?

Hidd3n

New Member
A piece of C++ I've been asked to look at is performing poorly due to an inordinate number of invocations of "new" on objects we use to store information about a node in an XML DOM tree. I've verified that new is the cause, using both AQTime and Very Sleepy profilers.These objects all contain several other object types and pointers to objects as members, so each new on a node object will invoke the constructors of all the member objects as well, which I guess is the reason each allocation takes so long. It also means we can't just call something like GlobalAlloc and request a big chunk of memory - it needs to be initialised afterwards. I've been investigating using preallocation techniques to mitigate this poor performance, but the ones I've seen involve requesting big chunks of uninitialised memory which isn't suitable for what I need, while others ultimately end up calling new anyway, cancelling out any performance gain we might observe so I'm wondering if there is another option I'm unaware of? I have a feeling what I'm asking for can't be done, that it's either retrieving uninitialised memory quickly or initialised memory slowly. Please prove me wrong :)Thanks
 
Back
Top