The “Harvard_architecture” (DSP, Microcontroller) and “von Neumann” or Princeton architecture (x86) are common Computer architectures.

Types of Memory:

  • CPU Registers
  • Cache (L1, L2)
  • Physical RAM
  • Virtual Memory
  • Permanent Storage (Hard Disks, Removable USB drives)


Cache Memory is faster, but smaller than standard RAM.

  • Level 1 cache
  • Level 2 cache is directly connected to the CPU (L2 Controller)
  • Level 3 cache is shared among all cores (Cache_coherence)

Obtain Information about the system cache:
sysctl -a hw (Mac)
lscpu | grep cache (Linux)

Approximate timing for various operations on a typical PC: []


Beside fragmented memory, the pyhiscal RAM memory can be exhausted. For example by reading a large Video File.

Another problem arises, when different programs or threads are allowed to access the same memory address. Overwrite data or Security related reading sensitive data.

Virtual memory separates the physical computer memory from the used memory over a mapping function, that redirects to a real address for the program.

Memory Layout

Memory in Programming:

In C++ we can verify the memory location, in a simple for int loop, the memory address increments by size of int.
But a Matrix can be sequential in memory, and is not column based. Due to the “row major memory layout”.

Resource Management

In C++ one is responsible to handle memory and not to leak memory.
In C the use of allocation (malloc) and free are used to manual manage memory. In C++ the equivalent is new and delete. RAII is a idiom by wrapping memory-handling under the hood of a Resource-Manager Class (ie, new in the constructor, delete destructor). Copying, shallow copying…pointers, smart pointers and memory bugs are in the topic of my next post.

Written on February 27, 2021
[ c++  ]