Dynamic memory allocation
- An application may require an amount of memory not known beforehand
- An application may require to allocate some memory to some task, and reallocate it to some other task
later on
- Some data structures and associated operations may require dynamic memory (linked lists...)
⇒ C library provides malloc and free functions
Dynamic memory allocation
- Memory is allocated when the application requests it
- The application must release memory when no more used: no garbage collector
- The memory is allocated from the heap
Drawbacks of dynamic memory allocation
-
Several interwoven allocation/release cycles of memory blocks of different sizes may lead
to heap fragmentation
-
Allocation and release times are not deterministic (but not as bad as garbage collecting
for higher-level languages)
⇒ If possible, do not use dynamic memory allocation