home *** CD-ROM | disk | FTP | other *** search
- { (C) Copyright 1986-1992 MetaWare Incorporated; Santa Cruz, CA 95060. }
-
- { Heap intrinsics. Used by Pascal "new" and "dispose" but }
- { may also be used by the programmer. }
- { Multiple heaps are supported. }
- { Restriction on 8086 implementation: one may not allocate }
- { anything larger then 64356 bytes. }
-
- pragma c_include('implement.pf');
- pragma c_include('filep.pf');
- package Heap type Heap_index; -- is abstract.
- pragma Routine_aliasing_convention(Implement.RTE_aliasing);
-
- with Implement;
-
-
- type Heap_index = Cardinal;
-
- const Reserved_heap = Heap_index(0); --Mark/Release does not affect this heap
-
- { Create a new heap. }
- { You can get new and dispose to use this heap by setting Curr_heap; }
- { see below. }
- function New_heap():Heap_index; external;
- { Free all storage associated with heap H. }
- { This is more efficient than disposing or freeing each item at a time. }
- procedure Free_heap(H:Heap_index); external;
-
- { Allocate memory of size Len bytes in Curr_heap. }
- { If Malloc fails, it returns nil. }
- function Malloc(Len: Byte_count): Pointer; external;
-
- { Allocate memory of size Len bytes in Heap H }
- { If HMalloc fails, it returns nil. }
- function HMalloc(H: Heap_index; Len: Byte_count): Pointer; external;
-
- { Free a pointer returned by Malloc. }
- procedure Free(P: Pointer); external;
-
- { Increase or decrease the size of P's space to Len. }
- { Realloc will expand in-place if possible. }
- { Reallocation always occurs in the same heap that the }
- { original data was allocated in. }
- { If the re-allocation failed on expansion we leave the original
- memory alone. }
- function Realloc(P:Pointer; Len:Byte_count):Pointer; external;
-
- { NOTE: None of Malloc, Free, or Realloc "zero out" allocated }
- { memory. Such storage is set to "Heap_init_byte" defined below }
- { if the variable "Init_allocated_storage" is set True (which it }
- { is, by default). }
-
- { Conditional realloc. Returns one of three results. }
- { If Succeeded, P points to the newly allocated storage. }
- { If Retained_memory, P points }
- { to storage of the same length as the old storage, with the same }
- { contents, but NOT NECESSARILY AT THE SAME ADDRESS. If the request}
- { for more memory fails, a request is made for the old amount of }
- { memory, so that you can try to CRealloc again with a }
- { more modest request. Typically this is used to increase the }
- { size of an array by first attempting to double it; then, if that }
- { fails, increasing it only by a small amount. }
- { If Lost_memory, then not only could it not obtain the new memory, but}
- { it couldn't get the old back. This may be the case on some oper-}
- { ating systems. It is never True for MS-DOS 2.0. }
- type CRealloc_returns =
- (Succeeded, Lost_memory, Retained_memory);
- function CRealloc(var P:Pointer; Len:Byte_count):CRealloc_returns;
- external;
-
- { Dump all heaps. }
- procedure Dump_heap(F: Filep_type.Filep); external;
-
- { For debugging. }
- { If heap has a problem, you'll get a heap dump. }
- procedure Check_heap_integrity; external;
-
- { If the flag below is set, heap integrity will be checked upon new/dispose }
- { or malloc/realloc/free. }
- { Heap_init_byte is what newly allocated storage is initialized with,}
- { if Init_allocated_storage is True. }
- { Curr_heap is the current heap from which data is allocated (unles }
- { HMalloc is used to allocate from a specific heap). You can freely }
- { assign Curr_heap any valid Heap_index. }
- var Check_heap_integrity_flag: Boolean;
- Heap_init_byte:char;
- Init_allocated_storage:Boolean;
- Curr_heap: Heap_index;
-
- { 8086 systems only: }
- { 2.8 release:
- -- Allocating objects > 64K in size (8086/286 only):
- function Halloc(Elements:Longint; Esize: Cardinal):_huge Address; External;
- procedure Hfree(_huge Address); External;
- }
- end;
- pragma Alias(Heap,Implement.RTE || 'heap');
-