Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Heavy malloc()/free() load and threads

Reply
Thread Tools

Re: Heavy malloc()/free() load and threads

 
 
Jonathan de Boyne Pollard
Guest
Posts: n/a
 
      03-20-2010


However, I wouldn't want all the dozens of apps on my desktop to all refuse to return memory back to the system just because they might want it again at some point in the future (thus unnecessarily forcing swapping to disk or a memory upgrade). Unless there is a very specific reason to think that performance is critical, my personal view is that it's polite for a userspace app to return memory back to the underlying system whenever it is reasonably possible.




malloc may or may not return memory to the system. Usually, it won't, except in fringe cases (eg 'large allocations' done via mmap). Memory allocations which originally happened by calling brk/sbrk cannot easily be returned to the system, anyway, only if freeing them happens to release a chunk of memory just below the current break.




On the contrary, usually it will.  I'm revising my estimate of the quality of your "50 — 300 lines of code" implementation downwards as a result of this statement, because you are erroneously conflating allocating address space with committing pages.  Most implementations that I am familiar with were written by people that didn't make this mistake. 




My implementation (more correctly, one of my implementations (- calls the OS/2 DosSetMem() function to commit partially used pages and de-commit wholly unused pages within the heap arena as necessary.  Several Win32 implementations that I'm aware of call VirtualAlloc() to commit and de-commit pages within arenas.  (For a good explanation of this process, see Matt Pietrek's dissection of the DOS-Windows 9x HeapAlloc() function in his Windows 95 System Programming Secrets book.)  The GNU C library version 2.11.1 calls madvise() with the MADV_DONTNEED flag for wholly unused pages. 




The OS/2 and Win32 implementations are returning unused heap memory to the operating system as a matter of course.  The GNU C library is intending to do the same, and is doing the best that it can with the more limited system API that it has to work with, and the operating system bugs that it has to cope with. (See, for example, Linux kernel bug #6282, reported by Samuel Thibault in 2007.)


 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      03-20-2010
On 03/20/10 08:59 PM, Jonathan de Boyne Pollard wrote:

Please stop cross-posting to so many groups and worse still, snipping
attributions.

--
Ian Collins
 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      03-20-2010
Ian Collins <(E-Mail Removed)> wrote:

> On 03/20/10 08:59 PM, Jonathan de Boyne Pollard wrote:
>
> Please stop cross-posting to so many groups and worse still, snipping
> attributions.


Not to mention posting bloody HTML, in the raw. If you _must_ post HTML,
use the proper headers so that my server can dump it in the bit-bucket
in non-binary groups, as it should.

Richard
 
Reply With Quote
 
Rainer Weikusat
Guest
Posts: n/a
 
      03-21-2010
Jonathan de Boyne Pollard <(E-Mail Removed)>
writes:
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


In addition to the useless crosspost, the HTML is also unkind.
I was actually seriously trying to edit this into a readable text in
order to address your somewhat 'weird' statements about malloc
implementations not written by yourself but quickly grew tired of the
effort. Feel free to repost this in human-readable form and with a
selection of 'newsgroups' that lets you look less like a troll.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTPHandler 404 Under Heavy Load news.microsoft.com ASP .Net 2 07-21-2004 10:52 PM
PC Reboots under heavy LAN load PhilÅ Computer Support 3 06-12-2004 02:44 PM
How heavy is a litre of heavy water? anthonyberet Computer Support 19 04-10-2004 04:07 PM
Why are heavy-weight components heavy? Minti Java 4 02-12-2004 06:50 PM
Cocoon 2.1.0 with JBoss 3.2.1 freezez under heavy load Blazej Zak Java 2 11-19-2003 09:13 AM



Advertisments