[Interest] memory fragmentation?
graeme2 at argyllcms.com
Wed Aug 22 05:45:00 CEST 2012
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.
More information about the Interest