heap fragmentation & operator new

Andrew Haley aph@redhat.com
Mon Jun 23 09:48:00 GMT 2008


Burlen Loring 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 

I would like to see such evidence.  I don't even believe that this
is possible, given that libstdc++-v3 uses malloc for its new.  Here
it is:

_GLIBCXX_WEAK_DEFINITION void *
operator new (std::size_t sz, const std::nothrow_t&) throw()
{
  void *p;

  /* malloc (0) is unpredictable; avoid it.  */
  if (sz == 0)
    sz = 1;
  p = (void *) malloc (sz);
  while (p == 0)
    {
      new_handler handler = __new_handler;
      if (! handler)
	return 0;
      try
	{
	  handler ();
	}
      catch (bad_alloc &)
	{
	  return 0;
	}

      p = (void *) malloc (sz);
    }

  return p;
}

> and additionally we see that additionally realloc gives performance
> advantage.

It gives performance advantage over what, exactly?

Andrew.



More information about the Gcc-help mailing list