Release 10.1A: OpenEdge Development:
Programming 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 a `RETURN` parameter to the routine. Then, to complete `MEMPTR` initialization, you should 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.

> ##### 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 © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095