-- Heap.mesa (last edited by: McJones on: August 5, 1980 1:59 PM)
DIRECTORY
Space USING [Handle, nullHandle, PageCount, wordsPerPage];
Heap: DEFINITIONS IMPORTS Space =
BEGIN
-- Dynamic storage allocation: support for Mesa uncounted zones.
-- This interface allows the creation and management of an arbitrary number of heaps, or dynamic storage allocation pools, each corresponding to a Mesa uncounted zone. A heap may be in hyperspace or in the MDS.
-- It is intended that Mesa’s NEW and FREE be used to allocate and deallocate nodes from a heap (although for compatibility with existing code, explicit procedures for this purpose are also provided).
-- Types
NWords: TYPE = [0..32766); -- limit on node size
-- Constants
defaultSwapUnit: Space.PageCount = LAST[Space.PageCount]; -- initial or extension heap is one swap unit
minimumNodeSize: READONLY NWords; -- implementation limit on threshold
systemZone: READONLY UNCOUNTED ZONE;
systemMDSZone: READONLY MDSZone;
-- Creating and deleting heaps
Create: PROCEDURE [
initial: Space.PageCount,
parent: Space.Handle ← Space.nullHandle,
increment: Space.PageCount ← 1,
swapUnit: Space.PageCount ← defaultSwapUnit,
threshold: NWords ← minimumNodeSize, -- smaller allocation request will be rounded up to this size
largeNodeThreshold: NWords ← Space.wordsPerPage/2, -- larger allocation request will be in separate space
ownerChecking: BOOLEAN ← FALSE,
checking: BOOLEAN ← FALSE]
RETURNS [UNCOUNTED ZONE];
CreateMDS: PROCEDURE [
initial: Space.PageCount,
increment: Space.PageCount ← 1,
swapUnit: Space.PageCount ← defaultSwapUnit,
threshold: NWords ← minimumNodeSize, -- smaller allocation request will be rounded up to this size
largeNodeThreshold: NWords ← Space.wordsPerPage/2, -- larger allocation request will be in separate space
ownerChecking: BOOLEAN ← FALSE,
checking: BOOLEAN ← FALSE]
RETURNS [MDSZone];
Delete: PROCEDURE [z: UNCOUNTED ZONE, checkEmpty: BOOLEAN ← FALSE];
DeleteMDS: PROCEDURE [z: MDSZone, checkEmpty: BOOLEAN ← FALSE];
-- Miscellaneous
GetAttributes: PROCEDURE [z: UNCOUNTED ZONE] RETURNS [parent: Space.Handle, heapPages, largeNodePages, increment, swapUnit: Space.PageCount, threshold, largeNodeThreshold: NWords, ownerChecking, checking: BOOLEAN];
GetAttributesMDS: PROCEDURE [z: MDSZone] RETURNS [heapPages, largeNodePages, increment, swapUnit: Space.PageCount, threshold, largeNodeThreshold: NWords, ownerChecking, checking: BOOLEAN];
Expand: PROCEDURE [z: UNCOUNTED ZONE, pages: Space.PageCount];
ExpandMDS: PROCEDURE [z: MDSZone, pages: Space.PageCount];
Prune: PROCEDURE [z: UNCOUNTED ZONE];
PruneMDS: PROCEDURE [z: MDSZone];
CheckOwner: PROCEDURE [p: LONG POINTER];
SetChecking: PROCEDURE [z: UNCOUNTED ZONE, checking: BOOLEAN];
SetCheckingMDS: PROCEDURE [z: MDSZone, checking: BOOLEAN];
-- Errors
Error: ERROR [type: ErrorType];
ErrorType: TYPE = {unsuitableParent, insufficientSpace, invalidHeap, invalidNode, invalidZone, invalidOwner, otherError};
-- Synonyms
-- NOTE: These are provided only to ease conversion of existing client code;
-- it is preferable for clients to use uncounted zones and NEW and FREE directly.
Handle: TYPE = UNCOUNTED ZONE;
MDSHandle: TYPE = MDSZone;
MakeNode: PROCEDURE [z: UNCOUNTED ZONE ← systemZone, n: NWords] RETURNS [LONG POINTER];
FreeNode: PROCEDURE [z: UNCOUNTED ZONE ← systemZone, p: LONG POINTER];
MakeMDSNode: PROCEDURE [z: MDSZone ← systemMDSZone, n: NWords] RETURNS [POINTER];
FreeMDSNode: PROCEDURE [z: MDSZone ← systemMDSZone, p: POINTER];
MakeString: PROCEDURE [z: UNCOUNTED ZONE ← systemZone, maxlength: CARDINAL] RETURNS [LONG STRING] =
INLINE {RETURN[z.NEW[StringBody[maxlength]]]};
FreeString: PROCEDURE [z: UNCOUNTED ZONE ← systemZone, s: LONG STRING] =
INLINE {z.FREE[@s]}; -- note this sets local s to NIL
MakeMDSString: PROCEDURE [z: MDSZone ← systemMDSZone, maxlength: CARDINAL] RETURNS [STRING] =
INLINE {RETURN[z.NEW[StringBody[maxlength]]]};
FreeMDSString: PROCEDURE [z: MDSZone ← systemMDSZone, s: STRING] =
INLINE {z.FREE[@s]}; -- note this sets local s to NIL
END.
LOG
Time: May 23, 1980 1:14 PMBy: McJonesAction: Created file
Time: July 8, 1980 5:15 PMBy: McJonesAction: Adapted for new-style uncounted zones
Time: August 5, 1980 1:59 PMBy: McJonesAction: Added Expand[MDS]; systemZONE=>systemZone; invalidZONE=>invalidZone; converted {Make,Free}[MDS]String to INLINE; added [MDS]Handle synonyms; decreased LAST[NWords]