Initial revision
[ssr] / StraySrc / Libraries / Sapphire / sh / heap
1 ;
2 ; heap.sh
3 ;
4 ; A resizing, nonshifting heap
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Overview -------------------------------------------------------------
28 ;
29 ; Functions provided:
30 ;
31 ; heap_init
32 ; heap_useHeap
33 ; heap_info
34 ; heap_alloc
35 ; heap_free
36 ; heap_reAlloc
37
38 [ :LNOT::DEF:heap__dfn
39 GBLL heap__dfn
40
41 ; --- heap_init ---
42 ;
43 ; On entry: --
44 ;
45 ; On exit: --
46 ;
47 ; Use: Initialises the heap system for use.
48
49 IMPORT heap_init
50
51 ; --- heap_useHeap ---
52 ;
53 ; On entry: --
54 ;
55 ; On exit: --
56 ;
57 ; Use: Registers the resizing heap as the current allocator.
58
59 IMPORT heap_useHeap
60
61 ; --- heap_info ---
62 ;
63 ; On entry: --
64 ;
65 ; On exit: R0 == current heap size
66 ; R1 == amount of memory free in the heap
67 ; R2 == size of the largest block free
68 ;
69 ; Use: Describes the heap's current status.
70
71 IMPORT heap_info
72
73 ; --- heap_alloc ---
74 ;
75 ; On entry: R0 == size of block wanted
76 ;
77 ; On exit: CC if enough memory was found and
78 ; R0 == pointer to the block allocated
79 ; else CS and
80 ; R0 corrupted
81 ;
82 ; Use: Allocates a block of at least a given size from a heap. If
83 ; the heap is not big enough, more is claimed from the
84 ; operating system.
85
86 IMPORT heap_alloc
87
88 ; --- heap_free ---
89 ;
90 ; On entry: R0 == pointer to a block created with heap_alloc
91 ;
92 ; On exit: --
93 ;
94 ; Use: Frees a block allocated using heap_alloc. It tries to
95 ; shrink the heap as much as possible afterwards.
96
97 IMPORT heap_free
98
99 ; --- heap_reAlloc ---
100 ;
101 ; On entry: R0 == pointer to block whose size we want to change
102 ; R1 == the new size of the block
103 ;
104 ; On exit: CC if block was resized, and
105 ; R0 == pointer to the block (which may have moved)
106 ; else CS and
107 ; R0 corrupted
108 ;
109 ; Use: Changes the size of a heap block. If possible, the block's
110 ; position is unchanged, but this may not always be the case.
111 ;
112 ; Note that changing a block's size to 0 is permitted.
113
114 IMPORT heap_reAlloc
115
116 ]
117
118 ;----- That's all, folks ----------------------------------------------------
119
120 END