Chapter 14 Further Reading: Pointers and Dynamic Memory
Free Pascal Documentation
- Free Pascal Reference Guide, Chapter 3: Types — Pointers. The authoritative reference for pointer types in Free Pascal, including typed pointers, the
Pointertype, and pointer-related compiler directives. -
URL: https://www.freepascal.org/docs-html/ref/refch3.html
-
Free Pascal Programmer's Guide: Memory Management. Covers the heap manager,
New,Dispose,GetMem,FreeMem, and memory manager customization. -
URL: https://www.freepascal.org/docs-html/prog/progch3.html
-
Free Pascal Wiki: Dynamic Arrays and Pointers. Practical examples of dynamic memory usage patterns in Free Pascal.
- URL: https://wiki.freepascal.org/Pointer
Classic Textbooks
-
Wirth, Niklaus. Algorithms + Data Structures = Programs (1976). The original Pascal textbook by Pascal's creator. Chapter 4 covers dynamic information structures (linked lists, trees) with elegant clarity. The title of this book is one of our textbook's recurring themes.
-
Dale, Nell and Weems, Chip. Pascal Plus Data Structures (various editions). A thorough treatment of pointers, linked lists, stacks, queues, and trees in Pascal. Excellent for reinforcing the material in Chapters 14–17 of this textbook.
-
Kernighan, Brian W. and Ritchie, Dennis M. The C Programming Language, 2nd Edition (1988). Chapter 5 covers pointers and arrays in C. Reading this after Chapter 14 will solidify your understanding of how Pascal's pointer model maps to C's — and why C's additional flexibility is dangerous.
Memory Management Deep Dives
-
Wilson, Paul R. et al. "Dynamic Storage Allocation: A Survey and Critical Review" (1995). A comprehensive survey of heap allocation algorithms (first-fit, best-fit, buddy systems, etc.). Explains what happens "under the hood" when you call
NewandDispose. -
Hertz, Matthew and Berger, Emery D. "Quantifying the Performance of Garbage Collection vs. Explicit Memory Management" (2005). Compares the performance of manual memory management (
malloc/free) with garbage collection. Relevant to understanding why Pascal and C use explicit management while Java and Python use garbage collection.
Language Comparisons
-
Klabnik, Steve and Nichols, Carol. The Rust Programming Language ("The Rust Book"). Chapter 4 covers ownership, borrowing, and lifetimes — Rust's compile-time enforcement of the ownership discipline discussed in Section 14.8. Available free at https://doc.rust-lang.org/book/
-
Stroustrup, Bjarne. A Tour of C++, 3rd Edition (2022). Chapter 5 covers essential operations including move semantics, and Chapter 15 covers smart pointers (
unique_ptr,shared_ptr). Shows how C++ automates the manual discipline practiced in Pascal.
Debugging Tools
- Valgrind (Linux/macOS). A memory error detector that can find memory leaks, use-after-free, double frees, and buffer overflows in compiled programs. While it does not directly support Free Pascal, it works with any compiled executable and is invaluable for C/C++ development. Understanding its output requires exactly the mental model built in this chapter.
-
URL: https://valgrind.org/
-
Free Pascal HeapTrc Unit. Free Pascal's built-in heap trace facility. Adding
{$IFDEF DEBUG}uses heaptrc;{$ENDIF}to your program enables leak detection at runtime: when the program ends, it reports any unfreed allocations with their allocation site.
Historical Context
- Hoare, C. A. R. "Null References: The Billion Dollar Mistake" (QCon 2009 keynote). Tony Hoare, who introduced null references in ALGOL W (1965), calls the invention his "billion-dollar mistake" due to the countless bugs it has caused. This talk provides essential context for understanding why nil dereferences are so common and why modern languages (Rust, Swift, Kotlin) are moving toward eliminating nullable references.
Looking Ahead
- Chapter 15 builds on this chapter's linked nodes to implement complete singly linked list operations: insertion at any position, deletion, searching, and sorting.
- Chapter 16 uses linked lists (and arrays) to implement stacks and queues.
- Chapter 17 extends the single-pointer node to a two-pointer node for binary trees.