When writing a program, including system programming, there are a few different types of memory that can be leveraged by the author:
- Global memory
- Stack memory
- Heap memory
Global memory exists in the program itself, is allocated by the OS's loader, and generally exists in two different locations (assuming ELF binaries):
- .bss: zero-initialized (or uninitialized) memory
- .data: value-initialized memory
Consider the following example:
#include <iostream>int bss_mem = 0;int data_mem = 42;int main(){ std::cout << bss_mem << '\n'; std::cout << data_mem << '\n';}// > g++ -std=c++17 scratchpad.cpp; ./a.out// 0// 42
Although used a lot in system programming, global memory is usually discouraged in favor of stack ...