MAINSAIL Language Manual, Section 30.6

previous   next   top   contents   index   framed top   this page unframed


30.6. $addMemMngModule

Temporary feature: subject to change

Figure 30–6. $addMemMngModule
PROCEDURE   $addMemMngModule
                        (
POINTER($memMngModuledataSec);

The user may write a MODULE that provides PROCEDUREs to be invoked at the start and end of a garbage collection (garbage collections are not signaled through the exception mechanism, since the exception mechanism itself can trigger garbage collections).

A garbage collection interception MODULE's CLASS must have the predeclared CLASS $memMngModule as its prefix CLASS; see Figure 30–7.

Figure 30–7. The CLASS $memMngModule
CLASS $memMngModule (
    
PROCEDURE $startOfMemMng;
    
PROCEDURE $endOfMemMng;
);

The user indicates that a MODULE of the CLASS $memMngModule is to be a garbage collection interception MODULE by calling $addMemMngModule. dataSec is the data section of the MODULE. $addMemMngModule locks the data section in memory so that it is not swapped out and is therefore resident when called.

Immediately before a collection starts, $startOfMemMng in each garbage collection interception MODULE is called. PROCEDUREs are called in the order of most recently added MODULE (with $addMemMngModule) to least recently added.

Immediately after a garbage collection terminates, $endOfMemMng is called in each garbage collection MODULE, in the same order as for $startOfMemMng.

To prevent an infinite recursion, $collectLock is incremented before calls to $startOfMemMng and $endOfMemMng. Therefore, the user risks an Insufficient memory: exiting termination of MAINSAIL if a call to $startOfMemMng or $endOfMemMng allocates any data, either directly or indirectly through any system facilities that allocate data.

A MODULE is removed from the list of garbage collection interception MODULEs by means of a call to $removeMemMngModule.

The following is a sample garbage collection interception MODULE. The MODULE shown should be bound from a program, not invoked from MAINEX; otherwise, the FINAL PROCEDURE will execute immediately, removing the MODULE from the list of garbage collection interception MODULEs:

BEGIN "mmMsg"

MODULE($memMngModulemmMsg;

INITIAL PROCEDURE;
$addMemMngModule(thisDataSection);



FINAL PROCEDURE;
$removeMemMngModule(thisDataSection);



Assume ttyWrite cannot trigger a collection (true except
when using MAINEDIT in the present version of MAINSAIL):

PROCEDURE $startOfMemMng;
ttyWrite("Doing memory management..." & eol);



PROCEDURE $endOfMemMng;
ttyWrite("Done with memory management." & eol);

END "mmMsg"

previous   next   top   contents   index   framed top   this page unframed

MAINSAIL Language Manual, Section 30.6