Memory Allocation

Noun · Development

Definitions

  1. Memory Allocation is the process of reserving a portion of computer memory for use by a program. Static allocation happens at compile time for global variables and fixed-size arrays, with their memory determined before the program runs. Stack allocation handles function-local variables automatically, allocating when a function is called and freeing when it returns. Dynamic (heap) allocation occurs at runtime when the program needs memory of a size or lifetime not known at compile time, using functions like malloc/free in C, new/delete in C++, or automatic garbage collection in languages like Java, Python, and Go. Dynamic allocation is more flexible but slower, and mismanagement causes memory leaks (forgetting to free), dangling pointers (using freed memory), and fragmentation (inefficient use of available space). Memory allocators like jemalloc, tcmalloc, and mimalloc optimize for different workload patterns, and their choice can significantly impact application performance.

    In plain English: Asking the computer to set aside some memory space for your program to store data in, and getting it back when you're done.

    Example: "malloc returned NULL — you've run out of heap memory and your program is about to have a very bad time."

Etymology

1950s
Early computers use fixed memory partitioning. Programmers manage memory addresses manually.
1964
The Multics operating system introduces dynamic memory allocation with segments and pages.
1978
Kernighan and Ritchie's 'The C Programming Language' codifies malloc/free as the standard allocation API.
2010s
Garbage collectors in Java, Go, and .NET refine allocation strategies. Memory allocators like jemalloc and tcmalloc optimize for concurrency.

Origin Story

The Art of Parceling Out Precious Memory

Memory allocation is the process by which a program requests and receives blocks of memory from the operating system or runtime to store data. The concept has been central to computing since the earliest machines, but it became a distinct discipline as programs grew complex enough to need dynamic, runtime allocation rather than fixed, compile-time allocation. In the 1950s, FORTRAN programs declared all their variables at compile time, and the compiler assigned fixed memory locations. This was simple but inflexible. LISP, created by John McCarthy in 1958, introduced dynamic allocation out of necessity: its linked-list data structures could grow and shrink unpredictably at runtime. McCarthy also invented garbage collection to reclaim memory that was no longer in use. The C language (1970s) gave programmers explicit control via malloc() and free(), placing the burden of memory management squarely on the developer. This power came with risks: memory leaks (forgetting to free memory), double frees (freeing the same memory twice), and use-after-free bugs became endemic. Modern allocators like jemalloc, tcmalloc, and mimalloc use sophisticated strategies including thread-local caches, size-class binning, and arena-based allocation to balance speed, memory efficiency, and fragmentation resistance.

Context: Early computing, 1950s; dynamic allocation pioneered by LISP (1958)

Fun fact: Mozilla created jemalloc for Firefox specifically because the browser's memory allocator was so slow that it was the primary bottleneck for page rendering. The allocator was later adopted by Facebook, FreeBSD, and Redis.

Related Terms