EASI provides functions that allow the user to directly allocate and manage blocks of memory, and make it possible to build data structures such as trees and linked lists. In some situations however, considerable opportunities for misuse are available, making it possible to not only cause errors, but also to possibly terminate EASI itself. These powerful facilities should be used with care.
Pointers are special variables used to refer to allocated blocks of memory. Pointers also have types, indicating to EASI how a block of memory should be interpreted. It is possible to declare pointers for any of the basic types in EASI, as well as for structures. The keyword PTR is used in LOCAL and GLOBAL declaration statements to indicate that a variable is a pointer.
For example, the following statement will declare a pointer to a block of integers called "pData":
local integer ptr pData
When a pointer variable is declared it does not point to any block of memory; the pointer is said to be initialized to "NULL". NULL is a keyword in EASI, and can be used to test if a pointer is currently pointing to any data.
if ( pData = NULL ) print "The pointer is set to NULL"
A block of memory can be allocated using the EAlloc() intrinsic function. EAlloc() takes two arguments, the first is the type of the memory, and the second is the number of units of memory of that type to allocate. To allocate a block of 10 integers, use the statement:
pData = EAlloc( int, 10 )
The actual data being pointed to can then be manipulated using array style indexing:
pData[1] = 10 pData[2] = pData[1] + 5
The length of the block of data being pointed to can be obtained using the F$LEN() intrinsic function:
EASI>print f$len( pData ) 10
Pointers can be assigned to other pointers:
local int ptr pData2 pData2 = pData
In the above example, pData2 will be pointing to the same data as pData.
EASI>pData2[3] = 100 EASI>print pData[3] 100
A block of data can be reallocated to a larger size using the ERealloc() intrinsic function. ERealloc() takes the same arguments as EAlloc(), along with a third argument which is a pointer to the block of memory to be allocated to a larger size.
pData = ERealloc( int, 20, pData )
When a block of data is reallocated to a larger size, it may be necessary to move it within memory to a new location (EASI manages this automatically). The previous contents of the block of data will be maintained, however since the block may have moved, other pointers referring to the same memory may no longer be valid (and should be assumed to be invalid). In the preceding example, the second pointer "pData2" may no longer point to a valid block of memory, and should be either reassigned to "pData", or no longer used. When a block of data is reallocated to a smaller size, its previous contents will be truncated. Normally, the block would not be moved to the new location, however since EASI does not guarantee that, the other pointers referring to the same memory should be assumed to be invalid.
EASI performs boundary check when you access the array contents using array style indexing. An error message will pop up if your script tries to access data outside the currently allocated array.
When a block of data is no longer required, it should be released using the EFree() intrinsic:
call EFree( pData )
After being freed, the block of data should no longer be referred to.
© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.