Table of contents
1.
Introduction
2.
Runtime Memory
3.
Static Versus Dynamic Storage Allocation
3.1.
Static Storage
3.2.
Stack Storage
3.3.
Heap Storage
4.
Frequently Asked Questions
4.1.
What is runtime storage organization in compiler design?
4.2.
What is storage allocation?
4.3.
What is the difference between Stack and heap?
5.
Conclusion
Last Updated: Mar 27, 2024

Storage Organization

Author GAZAL ARORA
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?
Compiler Design

Introduction

The runtime environment is the structure of the target computer's registers and memory that manages memory and keeps track of information required to execute a program. The runtime support package is responsible for data object allocation and deallocation.
The target program executes in its own logical address space, including a location for each program value. The management and organization of this logical address space are shared between the compiler, operating system, and target machine. The operating system converts this logical address to a physical address, which is typically distributed throughout the memory.

Also see, Phases of Compiler

Runtime Memory

The runtime representation in the logical address space includes data and program areas. 

The runtime storage is assumed to be in blocks of contiguous bytes, where a byte is the smallest unit of addressable memory. A byte is eight bits long, while a machine word can be made from four bytes. The address of the first byte is used to store multibyte objects in consecutive bytes.

Also see, Runtime Environments

Static Versus Dynamic Storage Allocation

Storage management is concerned with the layout and allocation of data to memory locations in a runtime environment. Since the same name in a program text might refer to several locations at run time, these difficulties are tricky. 

Compile-time and runtime are distinguished by the terms static and dynamic, respectively. A storage-allocation decision is said to be static if it can be decided by the compiler based just on the program's text, rather than what the program does as it executes. On the other hand, a decision is dynamic if it can only be made while the program is running. 

Static Storage

  • Fully static runtime environments may be helpful for languages that do not support pointers, dynamic allocation, or recursive function calls.
  • Names are connected to storage locations in static allocation. If memory is generated at compile-time, it will be created only once in the static area. 
  • The dynamic data structure is supported by static allocation, which means memory is allocated only at build time and released after the application is finished.

Also See, Top Down Parsing

 

For dynamic storage allocation, several compilers employ a combination of the two strategies listed below:

Stack Storage

  • Storage is organized as a stack in static storage allocation.
  • When activation begins, an activation record is pushed into the stack, and when it ends, it is popped.
  • It runs on the last-in-first-out (LIFO) principle, and this allocation supports the recursion process.

Heap Storage

  • The most flexible allocation strategy is Heap Allocation.
  • Memory allocation and deallocation can occur at any time and in any location, depending on the user's needs.
  • Heap allocation is a technique for dynamically allocating memory to variables and claiming it back when the variables are no longer used.
  • It supports the recursion process.

You can also read about the memory hierarchy.

Frequently Asked Questions

What is runtime storage organization in compiler design?

The run-time environment is the structure of the target computer's registers and memory that manages memory and keeps track of information required to execute a program.

What is storage allocation?

The process of connecting a storage space with a variable so that the data items represented by the variable can be recorded internally is known as storage allocation. 

What is the difference between Stack and heap?

The memory space is divided into Stack space and Heap space. The stack space is mainly used to store how methods are executed and local variables. Heap memory employs dynamic allocation to allocate and deallocate memory blocks. Stack memory constantly kept blocks in LIFO(Last In First Out) order.

Conclusion

In this article, we learned about storage organization in compiler design. We learned that the runtime environment is the structure of the target computer's registers and memory that manages memory and keeps track of information required to execute a program.

To summarise, there are three types of Runtime Environments :

  1. Fully static
  2. Stack Based
  3. Fully Dynamic

We also learned that a storage-allocation decision is said to be static if it can be decided by the compiler based just on the program's text, rather than what the program does as it executes. On the other hand, a decision is dynamic if it can only be made while the program is running. 

To support heap management, garbage collection allows the run-time system to detect useless data components and reuse their storage, even if the programmer does not explicitly return their space. 

Recommended Articles

Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, Uber, Microsoft, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Cheers!

Live masterclass