Dynamic Memory Allocation in C Programming
Dynamic Memory Allocation in C Programming
Allocation in C
Programming
Why Dynamic Memory
Allocation?
• The memory layout of a program can be divided into four
segments.
• One segment of the memory is assigned to store the
instructions that need to be executed.
• Another section stores all the static or global variables
that are not declared inside a function.
• The next section of the memory stores all the information
of function calls and all the local variables. This is known
as the ‘Stack.’ The local variables are declared inside a
function. Their lifetime is only till the function is executing.
• Unlike the stack, the application’s heap is not fixed. Its size can vary.
• During the lifetime of the application, there is no set rule for the allocation or deallocation of
memory.
• The user can control how much memory to use from the heap and till what time to keep the data in
the memory during the application’s lifetime.
• Heap can grow as long as you do not run out of the memory on the system itself.
• Heap is also known as ‘free pool of memory’ or ‘free store of memory.’ Heap is also referred to as
‘dynamic memory.’
• The implementation of heap by the operating system, language runtime or the compiler depends
upon the individual system and can vary from system to system.
• An abstracted way of looking at the heap as a user is that it is a large free pool of memory available
to us that we can use according to our needs.