Computer memory stores information and data for immediate use. Memory is slower than registers but has a higher capacity. It is faster than secondary storage but has a lower capacity.
Much of modern memory is implemented using semiconductors (semiconductor memory), especially with transistors and other electrical components. Two main kinds of semiconductor memory include volatile and non-volatile memory. Non-volatile memory (NVM) can generally retain stored information even after power is removed. To contrast, volatile memory needs constant or regular power to retain data.
Data is typically stored in memory cells each storing one bit. This is extendible to storing huge amounts of data if necessary in words. Most computers store a byte at each memory location.
In hardware
We have two main parts of memory: a decoder and an array of memory cells. We can think about memory as a matrix of bit storage with the following parameters:
WEis the write enable. ForWE=0, the memory operates in read-mode. AtWE=1, the memory operates in write-mode.A[m-1:0]specifies the memory address. This is fed into a decoder that one-hot decodes it into each word.O[2^m-1:0]is the one-hot representation of the memory address.D[n-1:0]represents how many bits wide the memory is. Each bit can be input (written to) or output (read from).
Where refers to a “word” of memory data, corresponding to one row of the memory cell array, and where refers to the word width (i.e., 32 bits). The data lines are often bidirectional.
The decoder will change the binary addresses of each cell array into a one-hot code, i.e., they take in inputs and have outputs. -bit processors have address lines, called the address space of the computer. Most computers will store a byte at each memory location. Bigger memories get slower.1 Intuitively, there needs to be more circuitry for the decoder, the wires need to be longer, and so on. Longer wires mean a higher capacitance (and higher time constant). To mitigate this, we use cache memory.
The practice of using lower byte addresses for less significant bytes is little-endian. The opposite, where lower byte addresses are used for more significant bytes is big-endian.
Related concepts
- Types of memory
- Volatile memory
- RAM (random-access memory)
- Dynamic RAM (DRAM)
- Static RAM (SRAM)
- RAM (random-access memory)
- Non-volatile memory
- Read-only memory (ROM)
- Programmable ROM (PROM)
- Electrically-erasable PROM (EEPROM)
- Programmable ROM (PROM)
- Read-only memory (ROM)
- Volatile memory
- Memory timing
- Memory block
- High-bandwidth memory
- Computation
In software
Every computer program runs in memory. A useful diagram of a running program’s memory is below. This can be the reverse way (like in Nios II).
Programming languages are divided into memory-safe and memory-unsafe languages. Safe languages include out of the box a garbage collector to maintain user-allocated memory and prevent memory leaks. To contrast, memory-unsafe languages (like C/C++) allow generally broader manipulation of memory and pointers (that hold memory addresses).
The nullptr or NULL memory address is, by convention, set to address 0. However, this isn’t guaranteed by the language standards or architectures, so a literal word value of 0 is used instead by the compiler.
Related concepts
Resources
- What Every Programmer Should Know About Memory, by Ulrich Drepper