Guardian Programmer's Guide

Table Of Contents
Managing Memory
Guardian Programmer’s Guide 421922-014
17 - 26
Allocating Extended Data Segments
Example of Allocating Extended Data Segments
The following example allocates four flat segments of 100,000 bytes each. These flat
segments are identified by segment IDs 0 through 3:
OPTIONS := 0;
OPTIONS.<14> := 1;
FOR I := 0 TO 3 DO
BEGIN
SEGMENT^ID[I] := I;
SIZE := 100000D;
ERROR := SEGMENT_ALLOCATE_(SEGMENT^ID[I],
SIZE,
!swap^file^name:length!,
ERROR^DETAIL,
!pin!,
!segment^type!,
BASE^ADDRESS[I],
!max^size!,
OPTIONS);
IF ERROR <> 0 THEN CALL ERROR^HANDLER;
END;
The base-address output parameter receives the starting address of each allocated
segment.
The preceding example also supplies the optional error-detail parameter. This
parameter returns a value if the returned error parameter is nonzero. The
error-detail parameter provides more information about the error.
Managing Swap Space
Data pages in physical memory are regularly swapped to a disk file to release memory
for other needs. By default, swap space for an extended data segment is handled by
the Kernel-Managed Swap Facility (KMSF). (This is the preferred way to handle swap
space for an extended data segment.) For each CPU, KMSF manages one or more
swap files from which swap space is allocated for the processes in that CPU. For
more information about KMSF, refer to the Kernel-Managed Swap Facility (KMSF)
Manual.
Alternatively, you can specify that an extended data segment have its own swap file,
which can be a temporary file or a permanent file. You specify a swap file by supplying
the filename:filename-length parameter to the SEGMENT_ALLOCATE_
procedure. If you supply a file name that includes a file ID part, and if a file with that
name does not already exist, then the system creates a permanent swap file with that
name. You can also specify just the volume part of the file name, in which case the
system creates a temporary swap file on the specified volume.
If you specify the name of an existing file to use as a swap file, you must have read
access to the file if it is to be used for a read-only segment, or read/write access
otherwise.