; ; heap.sh ; ; A resizing, nonshifting heap ; ; © 1994-1998 Straylight ; ;----- Licensing note ------------------------------------------------------- ; ; This file is part of Straylight's Sapphire library. ; ; Sapphire is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2, or (at your option) ; any later version. ; ; Sapphire is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with Sapphire. If not, write to the Free Software Foundation, ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ;----- Overview ------------------------------------------------------------- ; ; Functions provided: ; ; heap_init ; heap_useHeap ; heap_info ; heap_alloc ; heap_free ; heap_reAlloc [ :LNOT::DEF:heap__dfn GBLL heap__dfn ; --- heap_init --- ; ; On entry: -- ; ; On exit: -- ; ; Use: Initialises the heap system for use. IMPORT heap_init ; --- heap_useHeap --- ; ; On entry: -- ; ; On exit: -- ; ; Use: Registers the resizing heap as the current allocator. IMPORT heap_useHeap ; --- heap_info --- ; ; On entry: -- ; ; On exit: R0 == current heap size ; R1 == amount of memory free in the heap ; R2 == size of the largest block free ; ; Use: Describes the heap's current status. IMPORT heap_info ; --- heap_alloc --- ; ; On entry: R0 == size of block wanted ; ; On exit: CC if enough memory was found and ; R0 == pointer to the block allocated ; else CS and ; R0 corrupted ; ; Use: Allocates a block of at least a given size from a heap. If ; the heap is not big enough, more is claimed from the ; operating system. IMPORT heap_alloc ; --- heap_free --- ; ; On entry: R0 == pointer to a block created with heap_alloc ; ; On exit: -- ; ; Use: Frees a block allocated using heap_alloc. It tries to ; shrink the heap as much as possible afterwards. IMPORT heap_free ; --- heap_reAlloc --- ; ; On entry: R0 == pointer to block whose size we want to change ; R1 == the new size of the block ; ; On exit: CC if block was resized, and ; R0 == pointer to the block (which may have moved) ; else CS and ; R0 corrupted ; ; Use: Changes the size of a heap block. If possible, the block's ; position is unchanged, but this may not always be the case. ; ; Note that changing a block's size to 0 is permitted. IMPORT heap_reAlloc ] ;----- That's all, folks ---------------------------------------------------- END