Guardian Programmer's Guide

Table Of Contents
Managing Memory
Guardian Programmer’s Guide 421922-014
17 - 42
Deallocating an Extended Data Segment
!length!,
ERROR^DETAIL,
@SEG^PTR);
IF ERROR <> 0 THEN CALL ERROR^HANDLER;
Deallocating an Extended Data Segment
When you have finished accessing an extended data segment, you can deallocate it by
supplying the appropriate segment ID to the SEGMENT_DEALLOCATE_ procedure.
The SEGMENT_DEALLOCATE_ procedure returns an error value of 0 if the
deallocation was successful; any other value indicates that the operation was
unsuccessful.
The following example deallocates extended data segments:
FOR I := 0 TO 9 DO
BEGIN
ERROR := SEGMENT_DEALLOCATE_(I,
!flags!,
ERROR^DETAIL);
IF ERROR <> 0 THEN...
END;
Once the segment is deallocated, the segment no longer exists in physical memory.
The swap file, however, retains the segment data if it is a permanent file. If a
temporary file is used as the swap file, or if the Kernel-Managed Swap Facility (KMSF)
managed the swap space, then the swap data is discarded.
Using Memory Pools
Memory pools provide a mechanism to help you manage extended data segments. A
memory pool is an area of an extended data segment, user data segment (TNS
processes), or globals-heap segment (TNS/R native processes) that your process
allocates and from which your process can obtain and release blocks of storage.
To use memory pools in extended data segments, you must perform the following
steps:
1. Allocate an extended data segment and, if the segment is a selectable segment,
make it the current segment. (SEGMENT_ALLOCATE_ and SEGMENT_USE_
procedures). (A flat segment does not need to be made current.)
2. Define all or a contiguous part of that extended data segment to be part of a
memory pool (POOL_DEFINE_ procedure).
3. Obtain blocks of storage from the memory pool when needed
(POOL_GETSPACE_ procedure or POOL_GETSPACE_PAGE_ procedure) and
return those storage blocks to the memory pool when no longer needed
(POOL_PUTSPACE_ procedure). You can later extend the pool with the
POOL_RESIZE_ procedure.