CountedVM.mesa
Copyright © 1985 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
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 [Interval, LogPageCount, PageNumber, VMPartition];
CountedVM: CEDAR DEFINITIONS
= BEGIN
Handle: TYPE = REF Object;
Object: TYPE = RECORD [interval: VM.Interval, pointer: LONG POINTER, words: INT];
Allocate: PROC [words: INT,
partition: VM.VMPartition ← normalVM, subRange: VM.Interval ← [0, 0],
start: VM.PageNumber ← 0, alignment: VM.LogPageCount ← 0, in64K: BOOLFALSE]
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.