In this chapter, we will delve into a key aspect of system programming on a modern OS—the management of dynamic (runtime) memory allocation and deallocation. We'll first cover the basic glibc APIs used to allocate and free memory dynamically. We'll then move beyond these basics, examining the program break within the VAS and the behavior of malloc(3) under differing circumstances.
We will then immerse the reader in a few advanced discussions: demand-paging, memory locking and protection, and the usage of the alloca API.
Code examples provide the reader with an opportunity to explore these topics in a hands-on manner.
In this chapter, we will cover the following topics:
- Basic glibc dynamic memory-management APIs and their correct usage in code
- The program break (and its management via the sbrk(3) API)
- The internal behavior of malloc(3...