Global, Local, Static, and Dynamic

Top  Previous  Next

Data declarations automatically allocate memory to store the data values. Global, Local, Static, and Dynamic are terms that describe types of memory allocation.

The terms "Global" and "Local" refer to the visibility of data (also known as its "scope"):

·

"Global" means the data is visible to all procedures in the program.

·

"Local" means the data has limited visibility. This may be limited to one PROCEDURE or ROUTINE, or limited to a specific set of procedures in a single source module.

The terms "Static" and "Dynamic" refer to the persistence of the data's memory allocation:

·

"Static" means the data is allocated memory that is not released until the entire program is finished executing.

·

"Dynamic" means the data is allocated memory at run time. Data declared locally for the PROCEDURE or ROUTINE is allocated on the stack of the thread called to that PROCEDURE or ROUTINE. The stack memory allocated for such data is released on returning to the caller.

·

"Dynamic" also means that data is allocated by the program in the heap with the use of an explicit NEW, or implicitly, by some runtime library statements (assignment to ANY variables, ADDing to a QUEUE, etc.). Memory blocks allocated in the heap exist until their explicit releasing: DISPOSE for NEWed variables, FREE or DELETE for QUEUEs, etc.

See Also: Scope of variables and type declarations