Storage Allocation

The different ways to allocate memory are:

  • Static storage allocation
  • Stack storage allocation
  • Heap storage allocation

Static Storage Allocation

  • In static allocation, names are bound to storage locations.
  • If memory is created at compile time then the memory will be created in static area and only once.
  • Static allocation supports the dynamic data structure that means memory is created only at compile time and deallocated after program completion.
  • The drawback with static storage allocation is that the size and position of data objects should be known at compile time.
  • Another drawback is restriction of the recursion procedure.

Stack Storage Allocation

  • In static storage allocation, storage is organized as a stack.
  • An activation record is pushed into the stack when activation begins and it is popped when the activation end.
  • Activation record contains the locals so that they are bound to fresh storage in each activation record. The value of locals is deleted when the activation ends.
  • It works on the basis of last-in-first-out (LIFO) and this allocation supports the recursion process.

Heap Storage Allocation

  • Heap allocation is the most flexible allocation scheme.
  • Allocation and deallocation of memory can be done at any time and at any place depending upon the user's requirement.
  • Heap allocation is used to allocate memory to the variables dynamically and when the variables are no more used then claim it back.
  • Heap storage allocation supports the recursion process.

Example:

fact (int n)  

{  

   if (n<=1)  

       return 1;  

   else   

       return (n * fact(n-1));  

}  

fact (6)

The dynamic allocation is as follows:
Heap Storage Allocation

The document Storage Allocation is a part of the Computer Science Engineering (CSE) Course Compiler Design.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
Explore Courses for Computer Science Engineering (CSE) exam
Get EduRev Notes directly in your Google search
Related Searches
past year papers, Exam, practice quizzes, Storage Allocation, Storage Allocation, video lectures, ppt, pdf , Viva Questions, Sample Paper, Extra Questions, Summary, Important questions, mock tests for examination, study material, shortcuts and tricks, Previous Year Questions with Solutions, Semester Notes, Objective type Questions, Free, Storage Allocation, MCQs;