0% found this document useful (0 votes)
4 views21 pages

Dynamic Memory Allocation in C Programming

Dynamic memory allocation in C allows users to control memory usage from the heap, which is a flexible memory segment that can grow as needed. Unlike the stack, which has a fixed size and is limited to the duration of function execution, the heap provides a 'free pool of memory' that can be utilized throughout the application's lifetime. The implementation of the heap varies by system, but it offers an abstracted way for users to manage memory according to their requirements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views21 pages

Dynamic Memory Allocation in C Programming

Dynamic memory allocation in C allows users to control memory usage from the heap, which is a flexible memory segment that can grow as needed. Unlike the stack, which has a fixed size and is limited to the duration of function execution, the heap provides a 'free pool of memory' that can be utilized throughout the application's lifetime. The implementation of the heap varies by system, but it offers an abstracted way for users to manage memory according to their requirements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Dynamic Memory

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.

You might also like