chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Steel / h / mem
1 /*
2  * mem
3  *  Store handling for Steel
4  *
5  * version 1.00 6 September 1991
6  *
7  * © 1991-1998 Straylight
8  */
9
10 /*----- Licensing note ----------------------------------------------------*
11  *
12  * This file is part of Straylight's Steel library.
13  *
14  * Steel is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2, or (at your option)
17  * any later version.
18  *
19  * Steel is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with Steel.  If not, write to the Free Software Foundation,
26  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27  */
28
29 #ifndef __mem_h
30 #define __mem_h
31
32 #ifndef __size_t
33 #define __size_t
34 typedef unsigned int size_t;
35 #endif
36
37 typedef void *(*mem_allocProc)(size_t size);
38 typedef void (*mem_freeProc)(void *ptr);
39
40 /*
41  * void mem_flexdInit(void)
42  *
43  * Use
44  *  Initialises flex system.  If flex is already initialised, nothing
45  *  happens.  This call should be used in preference to flex_init().
46  */
47
48 void mem_flexdInit(const char *name, long max);
49 #define mem_flexInit(x) mem_flexdInit(0, 0)
50
51 /*
52  * void mem_heapInit(void)
53  *
54  * Use
55  *  Initialises heap system.  If heap is already initialised, nothing
56  *  happens.  If flex is not initialised, it is initialised for you.  This
57  *  call should be used in preference to heap_init().  Note that unlike
58  *  earlier versioms, this call will NOT set up ArmenLib to use heap by
59  *  default.  This would be duplicating the functionality of mem_useHeap().
60  */
61
62 void mem_heapInit(void);
63
64 /*
65  * void mem_useMalloc(void)
66  *
67  * Use
68  *  Makes ArmenLib use malloc() etc. for memory allocation.
69  */
70
71 void mem_useMalloc(void);
72
73 /*
74  * void mem_useHeap(void)
75  *
76  * Use
77  *  Makes ArmenLib use heap_alloc() etc. for memory allocation.  It is
78  *  initialised if necessary.
79  */
80
81 void mem_useHeap(void);
82
83 /*
84  * void mem_useUser(mem_allocProc alloc,mem_freeProc free)
85  *
86  * Use
87  *  Makes ArmenLib use your own user-defined memory allocation procedures.
88  *
89  * Parameters
90  *  mem_allocProc alloc == a routine to allocate a block of memory.  If a
91  *    block of sufficient size cannot be allocated, return 0.  Problems
92  *    about allocating blocks of 0 size are handled before your routine is
93  *    called.
94  *  mem_freeProc free == a routine to free a block of memory.  A valid
95  *    pointer will be passed to your routine.
96  */
97
98 void mem_useUser(mem_allocProc alloc,mem_freeProc free);
99
100 /*
101  * void mem_useRMA(void)
102  *
103  * Use
104  *  Makes ArmenLib use the RMA for memory allocation.
105  */
106
107 void mem_useRMA(void);
108
109 /*
110  * void *mem_RMAalloc(size_t size)
111  *
112  * Use
113  *  Allocates a block of memory from the relocatable module area.
114  *
115  * Parameters
116  *  size_t size == the size of the block
117  *
118  * Returns
119  *  A pointer to the block (or 0)
120  */
121
122 void *mem_RMAalloc(size_t size);
123
124 /*
125  * void mem_RMAfree(void *ptr)
126  *
127  * Use
128  *  Frees a block allocated using RMAalloc.
129  *
130  * Parameters
131  *  void *ptr == a pointer to the block.
132  */
133
134 void mem_RMAfree(void *ptr);
135
136 /*
137  * void *mem_alloc(size_t size)
138  *
139  * Use
140  *  Allocates a block of memory using malloc (or heap if initialised).  If
141  *  size is zero, or allocation fails then a NULL pointer is returned.
142  *
143  * Parameters
144  *  size_t size == how big you want the block.
145  *
146  * Returns
147  *  A pointer to the block allocated.
148  */
149
150 void *mem_alloc(size_t size);
151
152 /*
153  * void mem_free(void *ptr)
154  *
155  * Purpose
156  *  Frees a block of memory.  It must have been allocated using mem_alloc().
157  *  If ptr is NULL, then mem_free() does nothing.
158  *
159  * Parameters
160  *  void *ptr == the pointer returned by mem_alloc()
161  */
162
163 void mem_free(void *ptr);
164
165 /*
166  * size_t mem_sizeOfBlock(void *ptr)
167  *
168  * Use
169  *  Returns the allocated size of the block.
170  *
171  * Parameters
172  *  void *ptr == the pointer to the block
173  *
174  * Returns
175  *  The size of the block.
176  */
177
178 size_t mem_sizeOfBlock(void *ptr);
179
180 /*
181  * void *mem_reAlloc(void *ptr,size_t newSize)
182  *
183  * Use
184  *  Alters the size of the block given.  If the block could not be resized,
185  *  its contents are unchanged.  Note that the block may move as a result of
186  *  this call.
187  *
188  * Parameters
189  *  void *ptr == a pointer to the block.  This may be NULL, in which case,
190  *    this call behaves exactly like mem_alloc().
191  *  size_t newSize == the new size to make the block.  This may be zero, in
192  *    which case the block is freed.
193  *
194  * Returns
195  *  A pointer to the block.
196  */
197
198 void *mem_reAlloc(void *ptr,size_t newSize);
199
200 /*
201  * void mem_allowFlexBudge(BOOL allow)
202  *
203  * Use
204  *  A slightly more sensible way to allow flex store to be shunted around.
205  *
206  * Parameters
207  *  BOOL allow == whether you want flex store to be shifted around willy-
208  *    nilly.
209  */
210
211 void mem_allowFlexBudge(BOOL allow);
212
213 #endif