Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Stack and heap are not separate chips, banks of RAM, or sets of CPU registers. Inside a running process they are conventional regions and allocation patterns within a virtual address space. CPU registers hold working state, such as the stack pointer and program counter, and they are not stack or heap storage. This article explains each layer in order, starting with the process’s view of memory and ending with physical backing.

Where stack and heap actually live

A process works with virtual addresses. The operating system and hardware translate those addresses to physical memory, so a pointer in a program names a location in that process’s own address space, not a fixed slot on a memory module. The Linux mmap(2) manual page describes the call as creating a mapping in the calling process’s virtual address space. The top(1) manual page describes virtual memory as an abstraction over physical addresses that helps keep each process’s address space isolated.

Stack and heap as a simplified model

Michael Kerrisk’s 2026 training text, Linux System Programming Essentials, uses a simplified process layout. In that model the stack holds function-local variables and call-linkage information, and the heap holds dynamically allocated memory. The model is useful for reasoning about programs, but it is a teaching diagram rather than a map that every program follows.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The stack

In the simplified model, each function call gets a region for its local variables and the bookkeeping needed to return, including saved stack-pointer and program-counter values. That region is tied to the call. When the function returns, its local storage is no longer in use, and the next call can reuse the same part of the stack.

The heap

The heap holds memory that a program requests at run time, typically through an allocator such as the C library’s malloc(). Heap memory outlives the function that requested it and remains in use until the program releases it through the allocator’s interface.

Why the stack-down, heap-up diagram is not a universal rule

Kerrisk’s diagram draws the stack growing downward and the heap growing upward. That is a simplified Linux process layout. The mmap(2) manual page warns that the layout of process mappings may change across Linux, C library, and operating-system versions. Growth direction is therefore a property of a particular implementation, not a rule that applies to all computing.

What happens in CPU registers during a function call

Registers are the CPU’s working state. The stack is memory. A register can hold an address, such as the stack pointer, that the CPU uses to reach stack memory. The register itself is not a stack slot, and it does not store the stack’s contents.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

At the level of the simplified model, a call involves a few kinds of state:

  • The position in the caller’s code that must resume after the call returns.
  • The caller’s stack-pointer value, which marks where the caller’s frame sits.
  • The callee’s local variables, which the compiler may keep in registers, spill to stack memory, or remove entirely if the optimizer determines they are not needed.

Where each of these values is kept is set by the architecture’s calling convention (the ABI) and by the compiler. No single register convention applies across all architectures. In many common ABIs the call instruction pushes the return address onto the stack. Other architectures keep the return address in a dedicated link register, and the function may save it to the stack later. The model therefore describes what must be tracked, not which register holds which value on a given machine.

How Linux builds the regions

The program break: brk() and sbrk()

The brk(2) manual page describes brk() as setting the program break, the first location after the end of the uninitialized data segment. Raising the break allocates process memory, and lowering it deallocates memory. sbrk() changes the program’s data space by a given increment. These are Linux interfaces, and allocators do not rely on them alone.

Explicit mappings: mmap()

mmap(2) creates a mapping that can be file-backed or anonymous, and private or shared. Anonymous mappings are not backed by a file and are commonly used for memory that a program requests directly. The MAP_STACK flag is currently a no-op on Linux, according to the mmap(2) manual page, so it does not give a mapping special stack placement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Allocators combine the mechanisms

A modern allocator chooses among these mechanisms and organizes the memory it receives into chunks or arenas. A process’s heap-like memory is therefore often not one contiguous block. Describing it as a single heap block is an oversimplification.

Best Value
Auusda Laptop Computer, 15.6 Inch, 16GB RAM, 1TB SSD NVMe, Silver
  • 100 DAYS OF ZERO PRESSURE — Decide at 100 days, not 30
  • LOVE IT OR RETURN IT — Send it back within the trial. No questions
  • 3 YEARS OF COVERAGE — Defects under normal use, year after year
  • OUTLASTS THE REST — Others stop at one year. Yours goes for three
  • REAL HELP, 24/7 — Midnight or Sunday, help is one message away
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Physical backing

A virtual mapping is not the same as a permanently reserved physical-RAM address. The top(1) manual page lists memory forms tracked per process, including anonymous and file-backed memory, the stack, memory from malloc() and brk(), and explicit mappings. A mapped address may be backed by RAM, or it may not be resident at a given moment, depending on how the operating system manages it. The cited manuals do not describe one universal residency policy, so a program should not assume that every allocated byte is in physical RAM at once.

Limits and failure modes

The main limit on the address space is RLIMIT_AS, which caps the process’s virtual address-space size. The getrlimit(2) manual page documents it. When a process reaches the limit, brk(), mmap(), and mremap() can fail with ENOMEM. Automatic stack expansion can also fail, in which case the process receives SIGSEGV.

  • ENOMEM from brk(), mmap(), or mremap(): the request could not be satisfied, and a virtual address-space limit such as RLIMIT_AS is a documented cause.
  • SIGSEGV during stack growth: automatic stack expansion failed. Deep recursion or a large local allocation on the stack can lead to this.

To see the current virtual-memory limit in a Linux shell, run ulimit -v. A value of unlimited means no shell-imposed cap.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Stack and heap compared

Aspect Stack Heap
Lifetime and ownership Tied to function calls in the simplified model; local storage ends when the function returns From allocation until the program releases it through the allocator
Allocation and reclamation Call and return conventions Allocator API, such as malloc() and free() in C; underlying Linux calls are brk() and mmap()
Size and growth constraints Implementation-specific; automatic expansion can fail with SIGSEGV Limited by the address-space limit (RLIMIT_AS) and by allocator and operating-system behavior; calls can fail with ENOMEM
Position in the address space Conventional region; growth direction is implementation-specific Conventional region built from the program break and/or mappings; layout may change across versions
Performance differences Not established by the cited manuals Not established by the cited manuals

The table describes the Linux model. Other operating systems, C libraries, and runtimes may use different mechanisms and limits.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.