[net.sources] OSSI: SIMemory

biagioni@unc.UUCP (Edoardo Biagioni) (11/06/86)

(***************************************************************************)
(***                                                                     ***)
(***                                                                     ***)
(***                        O  S  S  I                                   ***)
(***                        ==========                                   ***)
(***                                                                     ***)
(**)               DEFINITION MODULE SIMemory;                           (**)
(***               ==========================                            ***)
(***                                                                     ***)
(***   This module defines procedures for dynamically allocating and     ***)
(***   deallocating heap memory.                                         ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Hardware:             independent                                 ***)
(***   Operating System:     independent                                 ***)
(***   Compiler:             independent                                 ***)
(***                                                                     ***)
(***   Version:      3.0                                                 ***)
(***   Implemented:  see copyright                                       ***)
(***   Date:         1986-03-12                                          ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Copyright 1984, 1985, 1986 by                                     ***)
(***      E. S. Biagioni                                                 ***)
(***      G. Heiser                                                      ***)
(***      K. Hinrichs                                                    ***)
(***      C. Muller                                                      ***)
(***                                                                     ***)
(***   Institut fuer Informatik                                          ***)
(***   ETH Zuerich                                                       ***)
(***   CH 8092 Zuerich                                                   ***)
(***   Switzerland                                                       ***)
(***                                                                     ***)
(***   Department of Computer Science                                    ***)
(***   University of North Carolina                                      ***)
(***   Chapel Hill, North Carolina 27514                                 ***)
(***   U.S.A.                                                            ***)
(***                                                                     ***)
(*** Permission to copy without fee all of this material is granted      ***)
(*** provided that the copies are not made or distributed for direct     ***)
(*** commercial advantage, that this OSSI copyright notice is            ***)
(*** included in the copy, that the module is not modified in any way    ***)
(*** except where necessary for compilation on a particular system,      ***)
(*** and that the module is always distributed in its original form.     ***)
(*** Distribution of this module in a modified form without including    ***)
(*** the original version is a violation of this copyright notice.       ***)
(***                                                                     ***)
(***---------------------------------------------------------------------***)
(***                                                                     ***)
(***   Updates:                                                          ***)
(***                                                                     ***)
(***                                                                     ***)
(***************************************************************************)

FROM SYSTEM IMPORT
  ADDRESS;


EXPORT QUALIFIED
  ALLOCATE,
  DEALLOCATE,
  StorageUnitsToBytes,
  BytesToStorageUnits,
  AllocateBytes,
  DeallocateBytes,
  PartialDeallocateBytes;


(* The procedures ALLOCATE and DEALLOCATE should only be used for the
   standard macros NEW and DISPOSE or for the equivalent constructs
   ALLOCATE (p, TSIZE (P)) and DEALLOCATE (p, TSIZE (P)).
   Storage allocated by a call to ALLOCATE must not be deallocated using
   DeallocateBytes or PartialDeallocateBytes, storage allocated by a call
   to AllocateBytes must not be deallocated using DEALLOCATE. *)

PROCEDURE ALLOCATE (VAR a: ADDRESS; size: CARDINAL);
(* allocates an area of the given size (number of storage units) and
   assigns its address to 'a'. If no space is available, the constant
   NIL is assigned to 'a'. If imported, this procedure will be used
   by the compiler when it finds a call to "NEW". *)

PROCEDURE DEALLOCATE (VAR a: ADDRESS; size: CARDINAL);
(* frees the area with the given size (number of storage units) at address
   'a', allocated by ALLOCATE, and assigns the constant NIL to 'a'.
   The behaviour of the procedure is undefined if 'a' or 'size' is illegal.
   If imported, this procedure will be used by the compiler when it finds
   a call to "DISPOSE" *)

PROCEDURE StorageUnitsToBytes (StorageUnits: CARDINAL): CARDINAL;
(* the number of bytes needed to store an object that requires
   the given number of storage units. *)

PROCEDURE BytesToStorageUnits (Bytes: CARDINAL): CARDINAL;
(* returns the number of storage units needed to store an object
   that is stored in the given number of bytes. *)

PROCEDURE AllocateBytes (VAR a: ADDRESS; size: CARDINAL);
(* allocates an area big enough for the given number of bytes: the actual
   amount of space allocated may be bigger. If no space is available the
   constant NIL is assigned to 'a'. *)

PROCEDURE DeallocateBytes (VAR a: ADDRESS; size: CARDINAL);
(* deallocates the area allocated by some AllocateBytes: the address and
   size MUST be IDENTICAL to those in the corresponding call to
   AllocateBytes or PartialDeallocateBytes *)

PROCEDURE PartialDeallocateBytes (VAR a: ADDRESS;
                                  originalsize, remainingsize: CARDINAL);
(* deallocates only (originalsize - remainingsize) BYTES from the space
   originally allocated using AllocateBytes. If a was originally a
   POINTER TO ARRAY [0..originalsize-1], it becomes a
   POINTER TO ARRAY [0..remainingsize-1], with array elements
   (0..remainingsize-1) being unchanged, and elements
   (remainingsize..originalsize-1) being inaccessible. If remainingsize
   is greater than or equal to originalsize, nothing is done. originalsize
   must be the allocation size of the storage (in bytes); remainingsize
   should be used when deallocating the storage, or as originalsize if
   deallocating part of the storage. Please note that the adress may
   be changed. *)

END SIMemory.