Pointers and memory

A pointer in Fortran is an alias, not a value, and the six lessons here treat it that way. POINTER and TARGET, association and ASSOCIATED, the procedure pointer and the pointer component of a node come first. The part ends on the choice between a pointer and an allocatable, and on what a program owns: deallocation, the leak valgrind finds, and the finaliser that releases a handle.

8.1 Pointers and TARGET POINTER, TARGET, the association => and a pointer that refers to another variable Open 8.2 Association, ASSOCIATED and NULLIFY ASSOCIATED, NULLIFY, a pointer to an array section, and a dangling target Open 8.3 Procedure pointers PROCEDURE(interface), POINTER, a pointer to a module procedure and a dispatch table Open 8.4 Pointer arrays and linked structures an array of pointers, a node with a pointer component, and a walk that frees as it goes Open 8.5 Pointer or allocatable what each owns, aliasing, the copy on assignment, and the rule of thumb Open 8.6 Deallocation, leaks and finalisation DEALLOCATE, automatic deallocation, a leak that valgrind shows, and a finaliser that closes a handle Open

Lessons