CountedVM.mesa
Copyright Ó 1985, 1986, 1991 by Xerox Corporation. All rights reserved.
Michael Plass, January 20, 1984 1:13:44 pm PST
Russ Atkinson (RRA) February 1, 1985 4:12:19 pm PST
Beach, February 22, 1985 1:55:15 pm PST
Doug Wyatt, February 26, 1985 10:13:28 am PST
Carl Hauser, March 24, 1988 2:53:30 pm PST
CountedVM provides a means for allocating large blocks of storage such that the storage will be returned when the reference is garbage collected.
DIRECTORY
VM USING [FalseBool, Interval, LogPageCount, NullInterval, VMPartition, ZeroPageNumber];
CountedVM: CEDAR DEFINITIONS
= BEGIN
Handle: TYPE = REF Object;
Object: TYPE = RECORD [interval: VM.Interval, pointer: POINTER, words: INT];
Allocate:
PROC [words:
INT,
partition:
VM.VMPartition ¬ normalVM, subRange:
VM.NullInterval ¬ [0, 0],
start:
VM.ZeroPageNumber ¬ 0, alignment:
VM.LogPageCount ¬ 0, in64K:
VM.FalseBool ¬
FALSE]
RETURNS [Handle];
Allocates the requested number of words of virtual memory, rounded up to a whole number of pages (the other arguments are passed unchanged to VM.Allocate and should ordinarily be defaulted). Returns a Handle designating the VM that was allocated. The client is responsible for holding onto the Handle for at least as long as it wants to be able to use the VM. The best way to reclaim the VM is to drop all copies of the handle and invoke the garbage collector.
Exceptions: raises VM.CantAllocate under the conditions described in the VM interface.
SimpleAllocate:
PROC [words:
INT]
RETURNS [Handle];
... equivalent to Allocate[words: words], defaulting all other parameters.
Free:
UNSAFE PROC [handle: Handle];
Explicitly frees the VM interval, and sets the fields of the object (interval ← nullInterval, pointer ← NIL, words ← 0). This procedure is used when it is known that the VM interval is no longer in use (watch out for dangling pointers, of course). When this is known with certainty, Free is better than letting the collector recover the storage, because the collector will reclaim it later, and because the collector is conservative (it may not collect the handle).
END.