On this page
Pointers, References & Indirection
Prev: Call Stack & Heap | Up: memory_and_execution | Next: Memory Management Models
Rel: Value vs. Reference Semantics, Memory Management Models, C Pointers & Pointer Arithmetic
Ref: Wikipedia — Pointer (Computer Programming)
Tags: #public #prog #programming #memory #pointers
Contents
Memory Addresses & Dereferencing
A pointer is a variable whose value is the numeric memory address of another value.
- Address-of (
&x): obtains the address wherexlives. - Dereference (
*p): reads or writes the value stored at the address held byp. - Managed references (Java, Python, JS) and borrowed references (Rust
&T/&mut T) are restricted pointers that forbid raw address arithmetic to preserve memory safety.
Variable p (at 0x1000) Variable x (at 0x2040)
┌────────────────────┐ ┌────────────────────┐
│ 0x2040 │ ────> │ 42 │
└────────────────────┘ └────────────────────┘
Classic Pointer Hazards
- Null dereference: dereferencing address
0(NULL/nullptr) crashes the process. - Dangling pointer / Use-after-free: pointing to stack or heap memory that has already been freed.
- Buffer overflow: pointer arithmetic reading/writing past the end of an allocated array.
Pointer Chasing & CPU Cache Locality
CPUs fetch memory in cache lines (typically 64 bytes). Contiguous arrays let hardware prefetchers stream data at full speed, whereas pointer-heavy linked lists or boxed objects scatter nodes across the heap (pointer chasing), causing orders-of-magnitude more cache misses.
Linked from
- tuts/c
- tuts/c/pointers_and_memory
- tuts/c/pointers_and_memory/pointers_and_pointer_arithmetic
- tuts/programming/algorithms_and_dsa/complexity_and_big_o
- tuts/programming/data_and_types/value_vs_reference_semantics
- tuts/programming/memory_and_execution
- tuts/programming/memory_and_execution/call_stack_and_heap
- tuts/programming/memory_and_execution/memory_management_models
- tuts/programming/memory_and_execution/pointers_references_and_indirection
Related notes
- tuts/c/pointers_and_memory/pointers_and_pointer_arithmetic Linked here; links to this page; shared tags: #memory, #pointers, #prog
- tuts/programming/data_and_types/value_vs_reference_semantics Linked here; links to this page; shared tags: #memory, #prog, #programming
- tuts/programming/memory_and_execution Linked here; links to this page; shared tags: #memory, #prog, #programming
- tuts/programming/memory_and_execution/call_stack_and_heap Linked here; links to this page; shared tags: #memory, #prog, #programming
- tuts/programming/memory_and_execution/memory_management_models Linked here; links to this page; shared tags: #memory, #prog, #programming
- tuts/c/pointers_and_memory links to this page; shared tags: #memory, #pointers, #prog
- tuts/programming/algorithms_and_dsa/complexity_and_big_o links to this page; shared tags: #prog, #programming
- tuts/c links to this page; shared tags: #prog
- tuts/programming/memory_and_execution/compilation_interpretation_and_jit shared tags: #memory, #prog, #programming
- tuts/c/compilation_and_internals/memory_layout_and_abi shared tags: #memory, #prog