Intel® Fortran Compiler 18.0 Developer Guide and Reference

Dynamic Allocation

Data objects can be static or dynamic. If a data object is static, a fixed amount of memory storage is created for it at compile time and is not freed until the program exits. If a data object is dynamic, memory storage for the object can be created (allocated), altered, or freed (deallocated) as a program executes.

Pointers, classes, deferred length character, allocatable scalars and arrays, and automatic arrays are dynamic data objects.

No storage space is created for a pointer until it is allocated with an ALLOCATE statement or until it is assigned to an allocated target. The storage space allocated is uninitialized.

An ALLOCATE statement can also be used to create storage for an allocatable array. A DEALLOCATE statement can be used to free the storage space reserved in a previous ALLOCATE statement. It also causes any pointers to become disassociated.

A pointer can be dynamically disassociated from a target by using a NULLIFY statement.

Automatic arrays differ from allocatable arrays in that they are automatically allocated and deallocated whenever you enter or leave a procedure, respectively.

Dynamic allocation occurs at run time and is handled by the Fortran Run-Time Library. There are several restrictions on allocation and deallocation that must be observed when these operations on a specific object are performed in program units that are separately compiled. When allocation and deallocation of an object are split between procedures in static code and dynamic shared libraries (.so files on Linux*) or dynamic-link libraries (DLLs on Windows*), the following applies:

NOTE

Dynamic memory allocation is limited by several factors, including swap file size and memory requirements of other applications that are running. Dynamic allocations that are too large or otherwise attempt to use the protected memory of other applications result in General Protection Fault errors. If you encounter an unexpectedly low limit, you might need to reset your virtual memory size through the Control Panel or redefine the swap file size.

Some programming techniques can help minimize memory requirements, such as using one large array instead of two or more individual arrays. Allocated arrays that are no longer needed should be deallocated.

See Also