|Navigation: Language Reference > 5 - Declaration Attributes > Variable and Entity Attributes >====== STATIC (set allocate static memory) ======|
The STATIC attribute specifies permanent memory allocation to a variable, GROUP, or data buffer of a QUEUE. If it is used with variables declared within a PROCEDURE, they are allocated statically instead of using stack memory. STATIC makes values contained in the local variable or QUEUE data buffer “persistent” from one call to the procedure to the next. Static local variables that require initialization are initialized once only during the first call to the respective procedure or routine. Regarding a QUEUE structure, only the data buffer is allocated static memory – QUEUE entries are always allocated memory dynamically on the heap.
A class method (except CONSTRUCT, DESTRUCT and methods defined in local classes (classes declared locally in a procedure)), field, property, or event can be STATIC. This makes them callable on a class even when no instance of the class has been created. If any instances of the class are created, they cannot be used to access the static member. Only one copy of static fields and events exists, and static methods and properties can only access static fields and static events. Static members are often used to represent data or calculations that do not change in response to object state; for instance, a math library might contain static methods for calculating sine and cosine.
A static member belongs to the type itself rather than to a specific object.
To access a static member of a class use the following syntax:
! Accessing the static method
SaveQueue QUEUE,STATIC !Static QUEUE data buffer
Field1 LONG !Value retained between
Field2 STRING !procedure calls
AcctFile STRING(64),STATIC !STATIC needed for use as
!variable in NAME attribute
Account SHORT !Account code
Date LONG !Transaction Date
Amount DECIMAL(13,2) !Transaction Amount