1987-05-13 14:36:45 +00:00
|
|
|
DEFINITION MODULE Storage;
|
1988-02-19 15:54:01 +00:00
|
|
|
(*
|
|
|
|
Module: Dynamic storage allocation
|
|
|
|
From: "Programming in Modula-2", 3rd, corrected edition, by N. Wirth
|
1994-06-24 14:02:31 +00:00
|
|
|
Version: $Id$
|
1988-02-19 15:54:01 +00:00
|
|
|
*)
|
1987-05-13 14:36:45 +00:00
|
|
|
|
1988-03-16 09:20:36 +00:00
|
|
|
(*
|
|
|
|
Wirth's 3rd edition certainly is confusing: mostly it uses Allocate, but
|
|
|
|
the module at the end of the book defines ALLOCATE. To avoid problems,
|
|
|
|
I included them both.
|
|
|
|
*)
|
|
|
|
|
1987-05-13 14:36:45 +00:00
|
|
|
FROM SYSTEM IMPORT ADDRESS;
|
|
|
|
|
|
|
|
PROCEDURE ALLOCATE(VAR a : ADDRESS; size : CARDINAL);
|
|
|
|
(* Allocate an area of the given size and return the address
|
|
|
|
in "a". If no space is available, the calling program is
|
|
|
|
killed.
|
|
|
|
*)
|
|
|
|
|
1988-03-16 09:20:36 +00:00
|
|
|
PROCEDURE Allocate(VAR a : ADDRESS; size : CARDINAL);
|
|
|
|
(* Identical to ALLOCATE *)
|
|
|
|
|
1987-05-13 14:36:45 +00:00
|
|
|
PROCEDURE DEALLOCATE(VAR a : ADDRESS; size : CARDINAL);
|
|
|
|
(* Free the area at address "a" with the given size. The area
|
|
|
|
must have been allocated by "ALLOCATE", with the same size.
|
|
|
|
*)
|
|
|
|
|
1988-03-16 09:20:36 +00:00
|
|
|
PROCEDURE Deallocate(VAR a : ADDRESS; size : CARDINAL);
|
|
|
|
(* Identical to DEALLOCATE *)
|
|
|
|
|
1987-05-13 14:36:45 +00:00
|
|
|
PROCEDURE Available(size : CARDINAL) : BOOLEAN;
|
1988-06-07 12:34:04 +00:00
|
|
|
(* Return TRUE if a contiguous area with the given size could be
|
|
|
|
allocated.
|
|
|
|
Notice that this only indicates if an ALLOCATE of this size
|
|
|
|
would succeed, and that it gives no indication of the total
|
|
|
|
available memory.
|
1987-05-13 14:36:45 +00:00
|
|
|
*)
|
|
|
|
|
|
|
|
END Storage.
|