
Introduction
Static memory allocation is known as Compile time memory allocation, which is used for the allocation of memory during the process of compilation of data of fixed size.
The compiler allocates memory for the variables present in the program. Static variables are permanently allocated during compilation.
Also see, Static and Dynamic Memory Allocation
Static allocation
Static allocation stands for the data allocated at a memory place with both known size as well as an address at compile time. Furthermore, the memory allocated stays allocated throughout the execution of the program. In most modern computers, their logical address space is divided into a data section (used for data) and a text section (used for code). Assemblers (i.e programs that convert symbolic machine code into binary machine code) maintain current address pointers to both the data area and text area. They also have pseudo instructions (directives) that can place labels at these addresses and move them. So we can allocate space for an array in the data space by placing a label at the current-address pointer in the data space and then moving the current-address pointer up by the size of the array. The code can use the label to access the array.
Also See, Top Down Parsing
Advantages
- Static memory allocation allocates memory to a variable that is declared ahead of time.
- Execution time is efficiently slower.
- It is easy to use in the context of programming.
Limitation
- The size of an array must be known at compile time if it is statically allocated, and the size can not change during execution.
- Though the array is only in use for a small fraction of the time, the space is allocated throughout the entire execution of the program.
- There is little reuse of statically allocated space within one program execution. The Fortran allows the programmer to specify that several statically allocated arrays can share the same space, but in modern languages, this feature is rarely seen.