Introduction to RAM
- Load → provide the address and get the corresponding data
- Write → Address + Data → update the state of the memory
Modern Technology Options and the Chart
- SRAM: super fast, can be on chip, next to the cpu pipeline (volatile - data is lost when the device is turned off)
- DRAM: denser than sram, offchip (volatile)
- Flash: super dense and cell wears out with each write
- Disk: tiny magnetic substrate with the highest density
<aside>
💡 On chip caches are cache for the memory and are managed by the hardware.
Registers are a cache for the on chip cache and is managed by the compiler.
Main memory is a cache for the disk and is managed by the operating system.
</aside>
Conducting a Memory Read Without Caches
- CPU places address A (rax) on the memory bus
- Main memory reads A from the memory bus, retrieves word val, and places it on the bus.
- Main memory reads data word val from the bus and stores it at address A.
Locality
- Principle of Locality: Programs tend to use data and instructions with addresses near or equal to those they have used recently
- Temporal Locality: Recently referenced items are likely to be referenced again in the near future
- Knowing that a loop will have a repeated action (reference sum or end condition)
- only has to do with branching and loops
- Spatial Locality: Items with nearby addresses tend to be referenced close together in time
- reference array elements in succession when looping through an array