Kyle Edwards

Memory

What is Memory?

Conceptually memory can be thought of a sequence of binary storage, commonly grouped into bytes (8 bits), words (the size depends on the architecture), and pages (which depend on the operating system).

Stack vs. Heap

In practice, processes divide contiguous memory into regions called the stack and the heap. The primary function of the stack is to handle memory allocation throughout the execution of the program throughout each function call.

Whenever an operation like a mathematical operator or a function call are initiated, the necessary values are referenced by their positions at the top of the stack (stack[stack_length - n] where n is the distance from the end of the stack). Scalar return values (or stack-bound collections like Rust arrays) are given room on the stack and set as well.

However, dynamic types like vectors do not have a static size. In most languages, any item on the stack must have a known size, so this other data must live in the heap instead. However because data is potentially getting allocated, reallocated, and freed in the heap by a lot of different parts of your application, it may not always be possible to get large free blocks. Performance concerns can arise as things need to get shifted around or the program needs to search through the heap for free space.

Heap Management

One strategy for heap management is a linked free list. Each free segment of memory is stored in a node containing the pointer to the next node, the current node’s size, and then the data contained by the block. For new allocations, it becomes necessary to search through this list to find either a first fit or a best fit. As deallocations occur, the list becomes increasingly fragmented. It becomes necessary to defragment the list.

Instruction Sets

Operating Systems

  1. File I/O
  2. Memory
    • Virtual memory, paging, segmentation
    • Virtual memory is disk space used for temporarily swapping out memory as needed.
    • Segmentation splits memory into chunks based on process but because whole code blocks are stored on disk/memory, it’s susceptible to fragmentation.
    • Pages (or page frames)
  3. Synchronization

Virtualization

Address Translation

Hardware address translation memory management unit (MMU) base and bound registers

Resources