heap fragmentation & operator new

me22 me22.ca@gmail.com
Sun Jun 22 17:51:00 GMT 2008


On Sun, Jun 22, 2008 at 13:09, Burlen Loring <burlen.loring@kitware.com> wrote:
> We have some complaints from our users that if we do not use
> malloc/realloc/free inside our container class, and rather we use operator
> new/delete, that we have heap fragmentation problem that leads to their
> running out of memory. We have evidence that its true and additionally we
> see that additionally realloc gives performance advantage. Is there anything
> we can do to actively combat heap fragmentation when using new/delete?  We
> already do the simple things like double the current size of the container
> if we need to extend. Can we tell the heap to de-fragment itself somehow?
> Are there any tools for dynamically observing the state of the heap? Are we
> "shooting our selves in the foot"(in terms of running out of memory) by
> using malloc and new together in the same library? Are there any must read
> books/documents that I should have read on this topic?
>

Well, it's simple for people to use a malloc/free allocator with
containers, so I don't think that's a big problem.  The only container
where realloc could really be used is vector, but until we get new
allocator concepts, that can be mostly mitigated by reserve.

I don't think that the heap can de-fragment itself, since it doesn't
know where the pointers are.



More information about the Gcc-help mailing list