[Interest] memory fragmentation?

pritam.ghanghas at gmail.com pritam.ghanghas at gmail.com
Wed Aug 22 07:29:44 CEST 2012

On Wed, Aug 22, 2012 at 9:15 AM, Graeme Gill <graeme2 at argyllcms.com> wrote:

> Till Oliver Knoll wrote:
> > Folks, I gave up checking for NULL pointers (C, malloc) or bad_alloc
> > exceptions (new, C++) a long time ago. I remember a discussion several
> > years ago (here on Qt interest?) about desktop memory managers actually
> > never returning a NULL pointer (or throwing an exception) when they
> > cannot allocate memory.
> This is simply not true when it comes to malloc. Malloc can and does
> return NULL on MSWin, OS X and Linux. I have some code that
> uses as much RAM as possible for computation caching, and the simplest
> portable way of sizing the virtual memory space is to malloc memory
> until it returns NULL, and then constrain the cache to be smaller
> than the available physical RAM and virtual memory space.
> [On 32 bit systems it is now common to have more RAM that
>  virtual memory space.]
> Even when operating below that limit, the cache can get a NULL (due
> to fragmentation or mallocs outside the caches purview), and responds
> by freeing up cache memory until the malloc succeeds.

Even I remember getting NULL when I was testing a use case when no memory
is available. I had filled the whole RAM by doing malloc() till i get NULL.
But I was doing malloc() for very small chunks (200byes) in a for loop.

> Graeme Gill.
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120822/e3a51a47/attachment.html>

More information about the Interest mailing list