Release 10.1A: OpenEdge Development:
Progress 4GL Reference

> ## SET-SIZE statement

> Manages memory associated with a MEMPTR variable. This includes allocating and associating a region of memory with an uninitialized MEMPTR variable, setting the size of a region allocated with a Windows dynamic link library (DLL) or UNIX shared library routine for a MEMPTR, and deallocating memory associated with a MEMPTR variable.

> Note: Does not apply to SpeedScript programming.

> #### Syntax

>     SET-SIZE ( memptr-var ) = size

> ``memptr-var``

> A reference to a variable defined as MEMPTR.

> ``size``

> An integer expression that specifies the allocated byte size of the region pointed to by `memptr-var`.

> Example

> In the following example, the SET-SIZE statement allocates 8 bytes of memory, associates the memory with the `ElipRegion` variable, and then initializes the region with four SHORT (2-byte) values:

> r-setsiz.p
>     DEFINE VARIABLE ElipRegion AS MEMPTR.

>     SET-SIZE(ElipRegion) = 8.
>     PUT-SHORT(ElipRegion, 1) = 10.
>     PUT-SHORT(ElipRegion, 3) = 10.
>     PUT-SHORT(ElipRegion, 5) = 200.
>     PUT-SHORT(ElipRegion, 7) = 50.

> #### Notes

> - If `memptr-var` has no memory allocated to it (is uninitialized), then the SET-SIZE statement allocates a memory region of the specified size.

> - If a MEMPTR variable is returned from a DLL or UNIX shared library routine that also allocates a memory region to it, then the SET-SIZE statement initializes the size of the existing region. Progress does not allocate a new region. This allows Progress to perform bounds checking on references to MEMPTR regions allocated outside Progress.

> Caution: You must know and specify the exact size of the memory region returned by the DLL routine from the type of structure it allocates. An incorrect size can result in data loss.

> - If the specified size is 0, the SET-SIZE statement deallocates (frees) any memory associated with `memptr-var`, making it available to reference a new memory region.

> - If the specified size is greater than 0 and `memptr-var` is fully initialized (associated with a memory region of a specified size), the SET-SIZE statement has no effect and leaves `memptr-var` unchanged.

> - After initializing a MEMPTR variable, you can obtain the address of (or pointer to) the region associated with the variable using the GET-POINTER-VALUE function. Use this to build structures that contain pointers to other structures, as required by some DLL or UNIX shared library routines.

> - For more information on accessing DLL routines from Progress, see OpenEdge Development: Programming Interfaces .

> #### See also

> GET-POINTER-VALUE function, GET-SIZE function

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