Presented By:
SATYA PRAKASH RANJAN
MCA/25005/18
CONTENTS
 What is memory allocation?
 Types of memory allocation
 Use of stack
 Use of heap
 Memory allocation model
4/13/2020 Footer Text 2
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
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
4/13/2020 Footer Text 5
Static vs Dynamic allocation
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
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
 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
 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
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
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
4/13/2020 Footer Text 12
Thank You!!!
4/13/2020 Footer Text 13

Memory Allocation to a process

  • 1.
    Presented By: SATYA PRAKASHRANJAN MCA/25005/18
  • 2.
    CONTENTS  What ismemory allocation?  Types of memory allocation  Use of stack  Use of heap  Memory allocation model 4/13/2020 Footer Text 2
  • 3.
    Meaning of memoryallocation  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 memoryallocation  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
  • 5.
    4/13/2020 Footer Text5 Static vs Dynamic allocation
  • 6.
    Memory assignment  Memoryassignment 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 memoryassignment  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 entryin 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 provisionsare 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 memoryassignment  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 modelfor 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
  • 12.
  • 13.