Re: Slow manual 'garbage collection' in C++ ??
brey_maastricht@hotmail.com wrote:
I have never heard before of a pool allocator but will Google for it.
One unfortunate side-effect of the C++ memory allocation scheme is
that most allocator implementations tend to be quite slow compared to
many other languages. 'news' and 'deletes' should often be avoided in
C++ not only because of the inherent memory leaking problems, but also
because of efficiency.
That being said, if all the objects you are allocating have the same
size, a pool/block allocator can speed up things considerably. For
example check this one:
http://warp.povusers.org/FSBAllocator/
(That library can even be modified so that if you are going to free
*all* the allocated objects anyways, and those objects do not have
destructors, it could just free them all in a single step so deleting
individual objects in a loop can be skipped completely. This makes
freeing all the objects an extremely fast operation. OTOH it would have
to be done very carefully, ie. you have to make sure that none of the
freed objects aren't referred to anymore anywhere.)