This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: heap fragmentation & operator new


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]