next up previous contents
Next: Pointers to Arrays vs Up: Pointers and Targets Previous: Status of a Pointer   Contents

Dynamic Targets

The ALLOCATE statement can reserve space to be the target of a pointer; in this case the pointer is not so much an alias of another variable, but a reference to an unnamed part of the heap storage.

For example,

allocate(PtoR,STAT=ierr) 
allocate(PtoA(n*n,2*k-1),STAT=ierr)
allocate new space for a single real, and then for a rank 2 array. If PtoA, PtoR were previously associated with other targets, those associations are broken (overwritten) by the ALLOCATE statements.

The deallocation statement

deallocate(PtoR,STAT=ierr)
breaks the connection between the pointer and its target and returns the freed space to the heap. The pointer remains in disassociated status.

We cannot use a pointer deallocate statement for objects that were not created by pointer allocation (e.g. allocate an allocatable matrix and associate a pointer to it, cannot just deallocate the pointer).

Note that nullifying the ``allocated'' pointer is possible

nullify(PtoR)
but is not recommended; nullification breaks the pointer-target connection, but does not free the target storage; this space will become inaccessible until the program terminates, unless it is pointed to by at least one more pointer.


next up previous contents
Next: Pointers to Arrays vs Up: Pointers and Targets Previous: Status of a Pointer   Contents
Adrian Sandu 2001-08-26