<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt">This seems like it would be slow, especially when you started using haddrist swap space, unless you have that turned off. I think that it would be better to just check against a limit yourself as to avoid allocating items that would be swapped.* <br><br>*I have no idea how your application uses the cache.<br><br><div><span><br></span></div><div><br></div>  <div style="font-family: Courier New, courier, monaco, monospace, sans-serif; font-size: 10pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1">  <b><span style="font-weight:bold;">From:</span></b> Graeme Gill <graeme2@argyllcms.com><br> <b><span style="font-weight: bold;">To:</span></b> interest@qt-project.org <br> <b><span style="font-weight:
 bold;">Sent:</span></b> Tuesday, August 21, 2012 11:45 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [Interest] memory fragmentation?<br> </font> </div> <br>
Till Oliver Knoll wrote:<br>> Folks, I gave up checking for NULL pointers (C, malloc) or bad_alloc <br>> exceptions (new, C++) a long time ago. I remember a discussion several <br>> years ago (here on Qt interest?) about desktop memory managers actually <br>> never returning a NULL pointer (or throwing an exception) when they <br>> cannot allocate memory.<br><br>This is simply not true when it comes to malloc. Malloc can and does<br>return NULL on MSWin, OS X and Linux. I have some code that<br>uses as much RAM as possible for computation caching, and the simplest<br>portable way of sizing the virtual memory space is to malloc memory<br>until it returns NULL, and then constrain the cache to be smaller<br>than the available physical RAM and virtual memory space.<br>[On 32 bit systems it is now common to have more RAM that<br> virtual memory space.]<br>Even when operating below that limit, the cache can get a NULL (due<br>to fragmentation or
 mallocs outside the caches purview), and responds<br>by freeing up cache memory until the malloc succeeds.<br><br>Graeme Gill.<br>_______________________________________________<br>Interest mailing list<br><a ymailto="mailto:Interest@qt-project.org" href="mailto:Interest@qt-project.org">Interest@qt-project.org</a><br>http://lists.qt-project.org/mailman/listinfo/interest<br><br><br> </div> </div>  </div></body></html>