| (* Library module defined by the International Standard | |
| Information technology - programming languages | |
| BS ISO/IEC 10514-1:1996E Part 1: Modula-2, Base Language. | |
| Copyright ISO/IEC (International Organization for Standardization | |
| and International Electrotechnical Commission) 1996-2021. | |
| It may be freely copied for the purpose of implementation (see page | |
| 707 of the Information technology - Programming languages Part 1: | |
| Modula-2, Base Language. BS ISO/IEC 10514-1:1996). *) | |
| DEFINITION MODULE Storage; | |
| (* Facilities for dynamically allocating and deallocating storage *) | |
| IMPORT SYSTEM; | |
| PROCEDURE ALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL); | |
| (* Allocates storage for a variable of size amount and assigns | |
| the address of this variable to addr. If there is insufficient | |
| unallocated storage to do this, the value NIL is assigned to addr. | |
| *) | |
| PROCEDURE DEALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL); | |
| (* Deallocates amount locations allocated by ALLOCATE for | |
| the storage of the variable addressed by addr and assigns | |
| the value NIL to addr. | |
| *) | |
| PROCEDURE REALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL); | |
| (* If addr is NIL then ALLOCATE is called otherwise it | |
| attempts to reallocate amount of storage. Effectively it | |
| calls ALLOCATE, copies the amount of data pointed to by | |
| addr into the new space and DEALLOCATES the addr. | |
| This procedure is a GNU extension. | |
| *) | |
| TYPE | |
| StorageExceptions = ( | |
| nilDeallocation, (* first argument to DEALLOCATE is NIL *) | |
| pointerToUnallocatedStorage, (* storage to deallocate not allocated by ALLOCATE *) | |
| wrongStorageToUnallocate (* amount to deallocate is not amount allocated *) | |
| ); | |
| PROCEDURE IsStorageException (): BOOLEAN; | |
| (* Returns TRUE if the current coroutine is in the exceptional | |
| execution state because of the raising of an exception from | |
| StorageExceptions; otherwise returns FALSE. | |
| *) | |
| PROCEDURE StorageException (): StorageExceptions; | |
| (* If the current coroutine is in the exceptional execution | |
| state because of the raising of an exception from | |
| StorageExceptions, returns the corresponding | |
| enumeration value, and otherwise raises an exception. | |
| *) | |
| END Storage. |