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

Discussion in 'C Programming' started by Jonathan de Boyne Pollard, Mar 20, 2010.

  1. 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.)
    Jonathan de Boyne Pollard, Mar 20, 2010
    #1
    1. Advertising

  2. Jonathan de Boyne Pollard

    Ian Collins Guest

    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
    Ian Collins, Mar 20, 2010
    #2
    1. Advertising

  3. Jonathan de Boyne Pollard

    Richard Bos Guest

    Ian Collins <> 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
    Richard Bos, Mar 20, 2010
    #3
  4. Jonathan de Boyne Pollard <>
    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.
    Rainer Weikusat, Mar 21, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.microsoft.com

    HTTPHandler 404 Under Heavy Load

    news.microsoft.com, Jun 16, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    481
    Darren Clark
    Jul 21, 2004
  2. Minti
    Replies:
    4
    Views:
    862
    John C. Bollinger
    Feb 12, 2004
  3. John
    Replies:
    13
    Views:
    701
  4. ravi
    Replies:
    0
    Views:
    450
  5. Peter
    Replies:
    34
    Views:
    1,942
    Richard Tobin
    Oct 22, 2004
Loading...

Share This Page