Hi,
Just wondering if somebody could point me to a good document on how the heap reclamation algorithm works for memory allocated in a user space program using the regular malloc/calloc functions. I am specifically interested in how effective it is in reclaiming memory. E.g., does it only reclaim from top of heap or does it reclaim from the complete heap? Are there multiple options for reclamation algorithms? Etc.
Thank you: Magnus
Magnus Karlsson Software Development Engineering Manager LSI Corporation Box 1024, Knarrarnäsgatan 15 SE-164 21 Kista, Sweden TEL +46 8 594 607 09 FAX +46 8 594 607 10 CELL +46 73 80 444 88 magnus.karlsson@lsi.com
On 21 November 2013 07:12, Karlsson, Magnus Magnus.Karlsson@lsi.com wrote:
Just wondering if somebody could point me to a good document on how the heap reclamation algorithm works for memory allocated in a user space program using the regular malloc/calloc functions.
Section 7.1.3, whose sub-sections include: "Implementation of malloc() and free()", "Tools and libraries for malloc debugging", and "Controlling and monitoring the malloc package", of Michael Kerrisk's "The Linux Programming Interface" (http://man7.org/tlpi/index.html) is one of the better reads of which I'm aware. He recommends reading the man pages for malloc_info, malloc_stats, mallopt, and mallinfo (among others) for more information.
In the C language, reclamation of allocated memory is usually driven by the application. When you free() some memory, internal structures know the size of what was previously allocated at the given location (i.e. what was given to you by malloc()) and simply release that back into the heap. There are ways to tweak the allocation of memory.