Open cswiercz opened 8 years ago
This website has a very good description on how to implement your own malloc which sheds light on the types of Linux system-level calls that are made.
Linked from the aforementioned website is this great analysis of how a program manages memory with the OS. I'm sure some of the things I said in class are corrected by the contents of the linked article.
This part of the article specifically describes the program heap behavior. To answer your question, the C library has heap allocation / memory management tools of its own. It seems that the OS-calls are only performed when the program sends a request for more heap.
Speaking of the heap, it comes next in our plunge into address space. The heap provides runtime memory allocation, like the stack, meant for data that must outlive the function doing the allocation, unlike the stack. Most languages provide heap management to programs. Satisfying memory requests is thus a joint affair between the language runtime and the kernel. In C, the interface to heap allocation is malloc() and friends, whereas in a garbage-collected language like C# the interface is the new keyword.
If there is enough space in the heap to satisfy a memory request, it can be handled by the language runtime without kernel involvement. Otherwise the heap is enlarged via the brk() system call (implementation) to make room for the requested block. Heap management is complex, requiring sophisticated algorithms that strive for speed and efficient memory usage in the face of our programs’ chaotic allocation patterns. The time needed to service a heap request can vary substantially. Real-time systems have special-purpose allocators to deal with this problem. Heaps also become fragmented, shown below:
Moved from uwhpsc-2016/homework1#40