Runtime Memory Organization: Code, Static Memory
Classified in Computers
Written at on English with a size of 2.37 KB.
Runtime Memory Organization
The organization of memory at runtime depends on the type of language (declarative, imperative), the compiler, and the operating system.
General Structure of Programming Languages
When you run a program, the OS loader allocates the required amount of memory and loads the code to be executed (stored in a file) into the code area.
The OS should detect collisions between the stack and the heap. In these cases, the program may abort, or the amount of allocated memory may be increased.
In memory paging systems, the above scheme can be fragmented and scattered between real memory and the virtual memory system.
Any reference to a storage location within the code should be relative to the position assigned to the process by the operating system.
Code Area
The code area contains the instructions to run the program, written in machine code. This is the translation to machine code for all procedures and functions of the program.
Code size and contents are calculated at compile time. The executable file contains all this code, along with information on the size of individual memory blocks needed. This information is used to load the program into memory for execution. The code is considered one compact block.
Some compilers, however, fragment the code into tabs (overlays) when the available memory is smaller than the size of the program. The overlays are sections of code that are loaded into memory separately. The compiler must decide how to group the functions into tabs so that there are not too many code loads during execution.
Static Memory
The compiler allocates a fixed memory location for each variable used in the program. It stores constants and global variables of the program. The memory allocation is done at compile time in a row, taking into account the size of the variable to assign. The address associated with each variable is constant and is relative to the start of the data segment (DS).
Compilers Based Solely on Static Memory
- They cannot deal with recursive functions.
- Each function is assigned an activation record that contains the parameters, local variables, and temporary variables of the function.
- The static memory contains the global variables and the sequence of activation records for each function.