2. CONTENTS
What is memory allocation?
Types of memory allocation
Use of stack
Use of heap
Memory allocation model
4/13/2020 Footer Text 2
3. Meaning of memory allocation
Processes are assigned a specific memory as
per their requirements during their run-
time.
When the program is finished its operation
or is idle, the memory is released and
allocated to another program or merged
within the primary memory.
4/13/2020 Footer Text 3
4. Types of memory allocation
Memory allocation has two core types;
Static Memory Allocation:
Memory allocated at compile time.
Dynamic Memory Allocation:
Memory allocated at run time.
4/13/2020 Footer Text 4
6. Memory assignment
Memory assignment usually follow these 2 type of
Data Structures based on the need and use cases
Stack Based
Heap Based
4/13/2020 Footer Text 6
7. Stack based memory assignment
Allocated memory includes variables whose scope is
associated with functions, procedures, or blocks, in a
program and parameters of function calls.
Memory is allocated when a function or block is
entered and is deallocated when it is exited.
Last-In First-Out (LIFO) nature of the
allocation/deallocation of data leads to Stack based
allocation
4/13/2020 Footer Text 7
8. Each entry in stack is of some standard size e.g. N bytes
A contiguous area of memory is reserved for the stack.
Only the last entry of the stack is accessible at any time.
Stack data is used to support function calls during
execution
The group of stack entries that pertain to one function
call is called a stack frame.
Stack frame is pushed on the stack during function call
4/13/2020 Footer Text 8
9. Two provisions are made to facilitate use of stack
frames:
The first entry in a stack frame is a pointer to the
previous stack frame on the stack. This entry facilitates
popping off of a stack frame.
A pointer called the frame base (FB) is used to point
to the start of the topmost stack frame in the
stack.
It helps in accessing various stack entries in the
stack frame.
4/13/2020 Footer Text 9
10. Heap based memory assignment
The program-controlled dynamic data (PCD data) of
the program is allocated by using Heap
Heap allows allocation/de-allocation of memory in
random order
An allocation request by a process returns with a
pointer to the allocated memory area in the heap, and
the process accesses the allocated memory area
through this pointer.
A de-allocation request returns a pointer to the
memory area to be de-allocated.
4/13/2020 Footer Text 10
11. Memory allocation model for a
process
The kernel creates a new process when a user issues a
command to execute a program.
At this time, it also decides how much memory it
should allocate to the process
Process needs memory for following components:
Code and static data of the program
Stack
Program-controlled dynamic data (PCD data)
4/13/2020 Footer Text 11