RAM Regions
RAM (random access memory) has regions that hold different data types during program execution.
Code (text) Segment
Program's executable code (instructions)
- holds compiled binary instructions
Data segment
Initialized data segment
- global and static variables initialized with a value before execution starts
Uninitialized data segment (BSS)
- Global and static variables that are declared but not initialized
Stack segment
Local variables, function call data (return address, function arguments), and control flow information
- Manages function call execution and keeps track of program flow.
Follows LIFO
Heap segment
Dynamically allocated memory
- Used for memory that needs to persist beyond the current function call or has a variable size
Closure for example, stores variables outside of the function context in heap.
- Heap is in RAM as a region for dynamically allocated memory.
Memory-mapped segment
- Data from files that are mapped directly into memory, shared libraries, or hardware-mapped memory.
- Primarily used for I/O operations and inter-process communication.