Data Section
-----------
Stack
-----------
Data Section (Static)
-----------
Text/ Code
- Data section stores globals and static data
- Shared between all functions in the process
- It’s a fixed size section
- Referenced directly by memory address
- Can store read only or read write
- Do need to watch out for concurrency
- If a thread is reading and other thread has updated the data, then the other thread need to communicate to the thread 1 to discard the read and read again
- Or else we would need to have mutex lock
Code:
A = 10
B = 20
int main() {
int x = A + B
}
- A & B are stored in the Data section
Data Section
-----------
1024 A
1020 B
-----------
- When a x = A + B is executed, CPU load A & B to it’s registers
- Since we are using DRAM, when doing memory read for A, the RAM sends 64 bytes of data to the CPU. So the other data is cached in the L level.
- And hence for B, CPU won’t need to do a memory read and will access it from the Cache