Storage Allocation | Compiler Design - Computer Science Engineering (CSE) PDF Download

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:
Storage Allocation | Compiler Design - Computer Science Engineering (CSE)

The document Storage Allocation | Compiler Design - Computer Science Engineering (CSE) 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)
26 videos|66 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

26 videos|66 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

shortcuts and tricks

,

video lectures

,

Objective type Questions

,

Storage Allocation | Compiler Design - Computer Science Engineering (CSE)

,

Exam

,

past year papers

,

Summary

,

Viva Questions

,

Storage Allocation | Compiler Design - Computer Science Engineering (CSE)

,

ppt

,

MCQs

,

study material

,

Semester Notes

,

Extra Questions

,

mock tests for examination

,

Previous Year Questions with Solutions

,

Storage Allocation | Compiler Design - Computer Science Engineering (CSE)

,

Sample Paper

,

practice quizzes

,

pdf

,

Free

,

Important questions

;