Guardian Programmer's Guide

Table Of Contents
Managing Memory
Guardian Programmer’s Guide 421922-014
17 - 28
Checking Whether an Extended Data Segment Is
Selectable or Flat
Checking Whether an Extended Data Segment Is Selectable or
Flat
Use the SEGMENT_GETINFO_ procedure to check whether a previously allocated
extended data segment is a selectable segment or flat segment. Given the
segment-id of an extended data segment, the SEGMENT_GETINFO_ procedure
returns an option flag indicating whether the segment is a flat segment or selectable
segment: if bit 9 of the usage-flags parameter is 1, the segment is a flat segment; if
bit 9 is 0, the segment is a selectable segment. This check is useful when writing
transportable programs for earlier systems.
Alternatively, you can check whether a segment is flat or selectable by testing the
base-address value returned by SEGMENT_ALLOCATE_. If the value is %2000000
(%H00080000), the segment is a selectable segment; otherwise, the segment is a flat
segment.
The following example checks the usage-flags parameter to determine the segment
type of extended data segment 1:
SEGMENT^ID := 1;
ERROR := SEGMENT_GETINFO_(SEGMENT^ID,
SIZE,
!swap^file:maxlength!,
!filename^length!,
ERROR^DETAIL,
BASE^ADDRESS,
USAGE^FLAGS);
IF ERROR <> 0 THEN CALL ERROR^HANDLER;
IF USAGE^FLAGS.<9> = 1 THEN
<Processing for flat segment>
ELSE
<Processing for selectable segment>
Making a Selectable Segment Current
Before you can access an allocated selectable segment, you must make the selectable
segment current by issuing a SEGMENT_USE_ procedure call. Your program can
refer only to the current selectable segment, and only one selectable segment can be
current at any time.
You specify the selectable segment you want to make current in the segm
ent-id
parameter of the SEGMENT_USE_ procedure call. This segment ID must be the
same as the segment ID you supplied to the SEGMENT_ALLOCATE_ procedure. If
the segment ID is invalid, the SEGMENT_USE_ procedure returns an error 4.
With successful completion of the SEGMENT_USE_ procedure call, the procedure
returns the previous value of the current segment ID in the optional old-segment-id
parameter. If no selectable segment was in use before the call to SEGMENT_USE_,
the procedure returns -1.