MALLOC() → HEAP_SPACE / FREE() → DEALLOC
POINTER = ADDRESS / *POINTER = VALUE
LIFETIME: DYNAMIC
STATE: REFERENCED
ASKiIMAN™ DOOR 04 / THE CODE / REALM 10
--:-- · -- --- ----

Ontological Layer: Physical Data Location

Memory & Pointers

Addressing, Lifetimes, and Dynamic Storage

The Coordinates of Data

Up to this realm, we structured data logically. Now, we confront where data physically lives. A variable is merely a human name for a physical memory address. Pointers give us direct control over these addresses, allowing us to build dynamic data structures that grow and shrink at runtime on the Heap, freeing us from the strict LIFO confines of the execution Stack. But with direct memory control comes the danger of leaks, dangling references, and fatal access violations.

PROGRAM VARIABLE → STACK FRAME vs DYNAMIC ALLOCATION → HEAP STORAGE → MEMORY ADDRESS → POINTER → DEREFERENCE VALUE → LIFETIME MANAGEMENT → MEMORY SAFETY

The 12 Memory Nodes

Ontological Mapping: From Stack Frames to Lost Allocations

GROUP 01

Stack vs Heap

  • Stack: Automatic, LIFO, Fast
  • Local variables & function frames
  • Heap: Dynamic, Unstructured, Manual
  • Runtime-created object lifecycles
GROUP 02 (A)

Pointers & Addresses

  • Variables exist at physical addresses
  • The Address-Of operator (&x)
  • A Pointer stores a memory address
  • Indirect access to data
GROUP 03

Dynamic Allocation

  • Requesting memory at runtime
  • malloc / calloc / realloc
  • Releasing memory (free)
  • Explicit ownership and lifetime
GROUP 02 (B)

Dereferencing

  • Accessing the target value (*ptr)
  • Reading through a pointer
  • Writing through a pointer
  • Modifying memory remotely
GROUP 02 (C)

Pointer Arithmetic

  • Adding/subtracting to addresses
  • Moves by sizeof(Type)
  • Iterating through contiguous arrays
  • ptr + 1 moves to the next element
GROUP 02 (D)

Null Pointers

  • Pointer holding 0x0 or NULL
  • Indicates "pointing nowhere"
  • Safe initialization state
  • Dereferencing NULL causes crash (Segfault)
VARIOUS

Pointers in Data Structures

  • The mechanism behind Linked Lists
  • Connecting Tree and Graph nodes
  • Dynamic growth of structures
  • Memory layout abstraction
GROUP 04 (A)

Memory Leaks

  • Allocated block loses its pointer
  • Memory remains marked "in use"
  • Program cannot reach or free it
  • Gradual exhaustion of Heap space
GROUP 04 (B)

Dangling Pointers

  • Memory block is freed
  • Pointer still holds the old address
  • Points to unallocated/reused space
  • Access causes unpredictable behavior
GROUP 04 (C)

Double Free

  • Calling free() on an already freed block
  • Corrupts allocator data structures
  • Severe security vulnerability
  • Fatal program crash
GROUP 02 (E)

References vs Pointers

  • Reference: Implicit alias, cannot be null
  • Cannot be reassigned after init (C++)
  • Pointer: Explicit variable holding address
  • Can be null, reassigned, arithmetic
FINAL PROTOCOL

12 — Memory Safety Laboratory

Node* p = malloc(sizeof(Node));
p->next = head; head = p;
free(p); // FATAL: Lost head link!
[1] TRACE ALLOCATIONS [2] CHECK DEREFERENCES [3] IDENTIFY LEAKS [4] NULLIFY AFTER FREE [5] VERIFY DS LINKS

Memory is finite and fragile. A single lost pointer unravels an entire data structure. By mastering explicit allocation, strict ownership, and safe pointer manipulation, we graduate from abstract theory to writing software that safely controls the physical machine.

SIMULATION RUNNING