Computer ScienceProgrammingMedium

Memory Allocation

Also known as:memory managementdynamic allocationheap allocation

Memory allocation is the process by which a program reserves a portion of a computer's RAM for its variables, data structures, and execution context. Allocation can be static (at compile time), automatic (on the call stack), or dynamic (on the heap at runtime using functions like malloc in C or new in C++/Java). Proper memory management is critical for performance and preventing bugs such as memory leaks, buffer overflows, and dangling pointers.

Types of Memory Allocation Compared

TypeLocationLifetimeManaged ByExample
StaticData segmentProgram lifetimeCompilerGlobal variables in C
Stack (automatic)StackFunction scopeCPU/OSLocal variables
Heap (dynamic)HeapUntil freedProgrammer / GCmalloc(), new
Memory-mappedVirtual memoryExplicit unmapOSmmap() in POSIX
RegisterCPU registersInstruction scopeCompilerLoop counter optimisation

Interactive Tools

Codecademy – C Memory Management

Open Tool

Brilliant – Computer Memory

Open Tool

Khan Academy – Computer Science

Open Tool
Diagram showing program memory layout including stack, heap, and data segments

Wikimedia Commons, CC BY-SA

Related Terms

From Latin "memoria" (memory) and "allocare" (to assign/place). The concept of dynamic memory allocation was formalised with the development of heap management in LISP (1960) and later standardised in C (1970s).

memoryheapstackallocationsystems-programmingc-programming