This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: heap fragmentation & operator new
- From: me22 <me22 dot ca at gmail dot com>
- To: "Burlen Loring" <burlen dot loring at kitware dot com>
- Cc: GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Sun, 22 Jun 2008 13:51:31 -0400
- Subject: Re: heap fragmentation & operator new
- References: <485E8748.7090903@kitware.com>
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.