Progress
External Program
Interfaces


Initializing and Uninitializing MEMPTR Variables

Typically when you initialize a MEMPTR variable, you use the SET-SIZE statement to allocate a region of memory for a specified size and associate it with the variable. You can also use a shared library routine to allocate the memory for a MEMPTR variable by passing the variable appropriately as an OUTPUT parameter to the routine that returns a structure. Then, to complete MEMPTR initialization, you must use the SET-SIZE statement so that Progress knows how big the memory area is.

You must know the exact size of data returned by the shared library routine to initialize the MEMPTR variable properly with the SET-SIZE statement. If you use an incorrect value, you might not be able to access the data as you expect. Note also that if you do not complete initialization of a shared library pre-initialized MEMPTR variable using the SET-SIZE statement, Progress does not perform any bounds checking when you read or modify contents of the structure.

CAUTION: If you specify a size that is too small, Progress prevents you from accessing parts of the returned structure that lie outside the specified region. However, if you specify a size that is too large (or do not complete initialization at all), you might cause a memory violation by inappropriately accessing memory outside the area of the structure. This can result in loss of data. To determine the size of structures allocated and returned by shared library routines, see the documentation for the routine you are calling.
Checking the Size Of a MEMPTR Variable

For any MEMPTR variable, you can determine the size of the structure by using the GET-SIZE function. If SET-SIZE was never called, Progress will return a value of 0.

Freeing Memory Associated With a MEMPTR Variable

The region of memory associated with a MEMPTR variable remains allocated until it is freed. In some cases, the shared library routine frees the memory; in other cases, the calling procedure must free the memory using the SET-SIZE statement to set its size to zero (0). Progress cannot free the memory for you. It is up to you to ensure that the memory is freed, depending on the functionality of each shared library routine you use.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095