11
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gsmemraw.h 11903 2010-11-16 22:49:26Z ray $ */
15
15
/* Client interface for "raw memory" allocator */
17
17
/* Initial version 02/03/1998 by John Desrosiers (soho@crl.com) */
25
/* gsmemraw was an abstract base class.
26
* it is no longer in use, instead use the concrete base class is gs_memory_t
25
/* gsmemraw was an abstract base class.
26
* it is no longer in use, instead use the concrete base class is gs_memory_t
27
27
* since gs_memory_t contains interfaces that must be availiable throughout the system
28
28
* is is unadvisable to have a class below it without these.
33
32
* This interface provides minimal memory allocation and freeing capability.
34
33
* It is meant to be used for "wholesale" allocation of blocks -- typically,
95
94
* actual alignment of the data in memory.
99
* Allocate bytes. The bytes are always aligned maximally
100
* if the processor requires alignment.
102
* Note that the object memory level can allocate bytes as
103
* either movable or immovable: raw memory blocks are
98
* Allocate bytes. The bytes are always aligned maximally
99
* if the processor requires alignment.
101
* Note that the object memory level can allocate bytes as
102
* either movable or immovable: raw memory blocks are
107
106
#define gs_memory_t_proc_alloc_bytes(proc, mem_t)\
108
107
byte *proc(mem_t *mem, uint nbytes, client_name_t cname)
110
109
#define gs_alloc_bytes_immovable(mem, nbytes, cname)\
111
110
((mem)->procs.alloc_bytes_immovable(mem, nbytes, cname))
114
* Resize an object to a new number of elements. At the raw
115
* memory level, the "element" is a byte; for object memory
116
* (gsmemory.h), the object may be an an array of either
117
* bytes or structures. The new size may be larger than,
118
* the same as, or smaller than the old. If the new size is
119
* the same as the old, resize_object returns the same
120
* object; otherwise, it preserves the first min(old_size,
121
* new_size) bytes of the object's contents.
113
* Resize an object to a new number of elements. At the raw
114
* memory level, the "element" is a byte; for object memory
115
* (gsmemory.h), the object may be an an array of either
116
* bytes or structures. The new size may be larger than,
117
* the same as, or smaller than the old. If the new size is
118
* the same as the old, resize_object returns the same
119
* object; otherwise, it preserves the first min(old_size,
120
* new_size) bytes of the object's contents.
124
123
#define gs_memory_t_proc_resize_object(proc, mem_t)\
125
124
void *proc(mem_t *mem, void *obj, uint new_num_elements,\
128
127
#define gs_resize_object(mem, obj, newn, cname)\
129
128
((mem)->procs.resize_object(mem, obj, newn, cname))
132
* Free an object (at the object memory level, this includes
133
* everything except strings). Note: data == 0 must be
134
* allowed, and must be a no-op.
131
* Free an object (at the object memory level, this includes
132
* everything except strings). Note: data == 0 must be
133
* allowed, and must be a no-op.
137
136
#define gs_memory_t_proc_free_object(proc, mem_t)\
138
137
void proc(mem_t *mem, void *data, client_name_t cname)
140
139
#define gs_free_object(mem, data, cname)\
141
140
((mem)->procs.free_object(mem, data, cname))
144
* Report status (assigned, used).
143
* Report status (assigned, used).
147
146
#define gs_memory_t_proc_status(proc, mem_t)\
148
147
void proc(mem_t *mem, gs_memory_status_t *status)
150
149
#define gs_memory_status(mem, pst)\
151
150
((mem)->procs.status(mem, pst))
154
* Return the stable allocator for this allocator. The
155
* stable allocator allocates from the same heap and in
156
* the same VM space, but is not subject to save and restore.
157
* (It is the client's responsibility to avoid creating
158
* dangling pointers.)
160
* Note that the stable allocator may be the same allocator
153
* Return the stable allocator for this allocator. The
154
* stable allocator allocates from the same heap and in
155
* the same VM space, but is not subject to save and restore.
156
* (It is the client's responsibility to avoid creating
157
* dangling pointers.)
159
* Note that the stable allocator may be the same allocator
164
163
#define gs_memory_t_proc_stable(proc, mem_t)\
165
164
mem_t *proc(mem_t *mem)
167
166
#define gs_memory_stable(mem)\
168
167
((mem)->procs.stable(mem))
171
* Free one or more of: data memory acquired by the allocator
172
* (FREE_ALL_DATA), overhead structures other than the
173
* allocator itself (FREE_ALL_STRUCTURES), and the allocator
174
* itself (FREE_ALL_ALLOCATOR). Note that this requires
175
* allocators to keep track of all the memory they have ever
176
* acquired, and where they acquired it. Note that this
177
* operation propagates to the stable allocator (if
170
* Free one or more of: data memory acquired by the allocator
171
* (FREE_ALL_DATA), overhead structures other than the
172
* allocator itself (FREE_ALL_STRUCTURES), and the allocator
173
* itself (FREE_ALL_ALLOCATOR). Note that this requires
174
* allocators to keep track of all the memory they have ever
175
* acquired, and where they acquired it. Note that this
176
* operation propagates to the stable allocator (if
181
180
#define FREE_ALL_DATA 1
182
181
#define FREE_ALL_STRUCTURES 2
193
192
#define gs_free_all(mem)\
194
193
gs_memory_free_all(mem, FREE_ALL_DATA, "(free_all)")
197
* Consolidate free space. This may be used as part of (or
198
* as an alternative to) garbage collection, or before
199
* giving up on an attempt to allocate.
196
* Consolidate free space. This may be used as part of (or
197
* as an alternative to) garbage collection, or before
198
* giving up on an attempt to allocate.
202
201
#define gs_memory_t_proc_consolidate_free(proc, mem_t)\
203
202
void proc(mem_t *mem)