Storage.def 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. DEFINITION MODULE Storage;
  2. (*
  3. Module: Dynamic storage allocation
  4. From: "Programming in Modula-2", 3rd, corrected edition, by N. Wirth
  5. Version: $Id$
  6. *)
  7. (*
  8. Wirth's 3rd edition certainly is confusing: mostly it uses Allocate, but
  9. the module at the end of the book defines ALLOCATE. To avoid problems,
  10. I included them both.
  11. *)
  12. FROM SYSTEM IMPORT ADDRESS;
  13. PROCEDURE ALLOCATE(VAR a : ADDRESS; size : CARDINAL);
  14. (* Allocate an area of the given size and return the address
  15. in "a". If no space is available, the calling program is
  16. killed.
  17. *)
  18. PROCEDURE Allocate(VAR a : ADDRESS; size : CARDINAL);
  19. (* Identical to ALLOCATE *)
  20. PROCEDURE DEALLOCATE(VAR a : ADDRESS; size : CARDINAL);
  21. (* Free the area at address "a" with the given size. The area
  22. must have been allocated by "ALLOCATE", with the same size.
  23. *)
  24. PROCEDURE Deallocate(VAR a : ADDRESS; size : CARDINAL);
  25. (* Identical to DEALLOCATE *)
  26. PROCEDURE Available(size : CARDINAL) : BOOLEAN;
  27. (* Return TRUE if a contiguous area with the given size could be
  28. allocated.
  29. Notice that this only indicates if an ALLOCATE of this size
  30. would succeed, and that it gives no indication of the total
  31. available memory.
  32. *)
  33. END Storage.