~ubuntu-branches/ubuntu/maverick/ncbi-tools6/maverick

« back to all changes in this revision

Viewing changes to connect/ncbi_heapmgr.h

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef NCBI_HEAPMGR__H
2
 
#define NCBI_HEAPMGR__H
 
1
#ifndef CONNECT___NCBI_HEAPMGR__H
 
2
#define CONNECT___NCBI_HEAPMGR__H
3
3
 
4
 
/*  $Id: ncbi_heapmgr.h,v 6.9 2001/07/03 20:23:46 lavr Exp $
 
4
/*  $Id: ncbi_heapmgr.h,v 6.20 2004/07/08 14:11:11 lavr Exp $
5
5
 * ===========================================================================
6
6
 *
7
7
 *                            PUBLIC DOMAIN NOTICE
31
31
 * File Description:
32
32
 *   Simple heap manager with a primitive garbage collection
33
33
 *
34
 
 * --------------------------------------------------------------------------
35
 
 * $Log: ncbi_heapmgr.h,v $
36
 
 * Revision 6.9  2001/07/03 20:23:46  lavr
37
 
 * Added function: HEAP_Copy()
38
 
 *
39
 
 * Revision 6.8  2001/06/19 20:16:19  lavr
40
 
 * Added #include <connect/ncbi_types.h>
41
 
 *
42
 
 * Revision 6.7  2001/06/19 19:09:35  lavr
43
 
 * Type change: size_t -> TNCBI_Size; time_t -> TNCBI_Time
44
 
 *
45
 
 * Revision 6.6  2000/10/05 21:25:45  lavr
46
 
 * ncbiconf.h removed
47
 
 *
48
 
 * Revision 6.5  2000/10/05 21:09:52  lavr
49
 
 * ncbiconf.h included
50
 
 *
51
 
 * Revision 6.4  2000/05/23 21:41:05  lavr
52
 
 * Alignment changed to 'double'
53
 
 *
54
 
 * Revision 6.3  2000/05/12 18:28:40  lavr
55
 
 * First working revision
56
 
 *
57
 
 * ==========================================================================
58
34
 */
59
35
 
60
36
#include <connect/ncbi_types.h>
61
37
 
 
38
 
 
39
/** @addtogroup ServiceSupport
 
40
 *
 
41
 * @{
 
42
 */
 
43
 
 
44
 
62
45
#ifdef __cplusplus
63
46
extern "C" {
64
47
#endif
80
63
 
81
64
/* Callback to expand the heap (a la 'realloc').
82
65
 * NOTE: the returned address must be aligned on a 'double' boundary!
 
66
 *
 
67
 *   old_base  |  new_size  |  Expected result
 
68
 * ------------+------------+--------------------------------------------------
 
69
 *   non-NULL  |     0      | Deallocate old_base and return 0
 
70
 *   non-NULL  |  non-zero  | Reallocate to the requested size, return new base
 
71
 *      0      |  non-zero  | Allocate (anew) and return base
 
72
 *      0      |     0      | Do nothing, return 0
 
73
 * ------------+------------+--------------------------------------------------
 
74
 * Note that reallocation can request either to expand or to shrink the
 
75
 * heap extent. When (re-)allocation fails, the callback should return 0.
 
76
 * When expected to return 0, this callback has to always do so.
83
77
 */
84
 
typedef char* (*FHEAP_Expand)
85
 
(char*      old_base,  /* current base of the heap to be expanded           */
86
 
 TNCBI_Size new_size   /* requested new heap size (zero to deallocate heap) */
 
78
typedef void* (*FHEAP_Expand)
 
79
(void*      old_base,  /* current base of the heap to be expanded           */
 
80
 TNCBI_Size new_size,  /* requested new heap size (zero to deallocate heap) */
 
81
 void*      arg        /* user-supplied argument, see HEAP_Create() below   */
87
82
 );
88
83
 
89
84
 
90
85
/* Create new heap.
91
86
 * NOTE: the initial heap base must be aligned on a 'double' boundary!
92
87
 */
93
 
HEAP HEAP_Create
94
 
(char*        base,        /* initial heap base (use "expand" if NULL) */
 
88
extern NCBI_XCONNECT_EXPORT HEAP HEAP_Create
 
89
(void*        base,        /* initial heap base (use "expand" if NULL) */
95
90
 TNCBI_Size   size,        /* initial heap size                        */
96
91
 TNCBI_Size   chunk_size,  /* minimal increment size                   */
97
 
 FHEAP_Expand expand       /* NULL if not expandable                   */
 
92
 FHEAP_Expand expand,      /* NULL if not expandable                   */
 
93
 void*        arg          /* arg to pass to expand (if any)           */
98
94
 );
99
95
 
100
96
 
101
97
/* Attach to an already existing heap (in read-only mode).
102
98
 */
103
 
HEAP HEAP_Attach
104
 
(char* base                /* base of the heap to attach to */
 
99
extern NCBI_XCONNECT_EXPORT HEAP HEAP_Attach
 
100
(const void* base          /* base of the heap to attach to */
 
101
 );
 
102
 
 
103
extern NCBI_XCONNECT_EXPORT HEAP HEAP_AttachEx
 
104
(const void* base,
 
105
 TNCBI_Size  size
105
106
 );
106
107
 
107
108
 
108
109
/* Allocate a new block of memory in the heap.
109
110
 */
110
 
SHEAP_Block* HEAP_Alloc
 
111
extern NCBI_XCONNECT_EXPORT SHEAP_Block* HEAP_Alloc
111
112
(HEAP       heap,          /* heap handle                       */
112
113
 TNCBI_Size size           /* data size of the block to contain */
113
114
 );
115
116
 
116
117
/* Deallocate block pointed by "block_ptr".
117
118
 */
118
 
void HEAP_Free
 
119
extern NCBI_XCONNECT_EXPORT void HEAP_Free
119
120
(HEAP         heap,        /* heap handle         */
120
121
 SHEAP_Block* block_ptr    /* block to deallocate */
121
122
 );
125
126
 * Return pointer to the block following block "prev_block".
126
127
 * Return NULL if "prev_block" is the last block of the heap.
127
128
 */
128
 
SHEAP_Block* HEAP_Walk
129
 
(HEAP               heap,  /* heap handle                                  */
 
129
extern NCBI_XCONNECT_EXPORT SHEAP_Block* HEAP_Walk
 
130
(const HEAP         heap,  /* heap handle                                  */
130
131
 const SHEAP_Block* prev   /* (if 0, then get the first block of the heap) */
131
132
 );
132
133
 
133
134
 
134
 
/* Make a snapshot of a given heap. Returne a read-only heap
 
135
/* Trim the heap, making garbage collection first. Returned is
 
136
 * the size of the resultant heap, which has its last block trimmed
 
137
 * to the size of heap chunk size as specified at the time of the
 
138
 * heap creation.  No change in size is made if the last block is
 
139
 * not free or large enough to allow the trimming. 0 returned on
 
140
 * NULL or read-only heaps, or if an error has occurred.
 
141
 */
 
142
extern NCBI_XCONNECT_EXPORT TNCBI_Size HEAP_Trim(HEAP heap);
 
143
 
 
144
 
 
145
/* Make a snapshot of a given heap.  Return a read-only heap
135
146
 * (like one after HEAP_Attach), which must be freed by a call to
136
147
 * either HEAP_Detach or HEAP_Destroy when no longer needed.
 
148
 * If a non-zero number provided (serial number) it is stored
 
149
 * in the heap descriptor (zero serial is always turned into 1).
137
150
 */
138
 
HEAP HEAP_Copy(HEAP orig);
 
151
extern NCBI_XCONNECT_EXPORT HEAP HEAP_CopySerial
 
152
(const HEAP orig,         /* original heap to copy from               */
 
153
 size_t     extra,        /* extra amount to add past the heap extent */
 
154
 int        serial        /* serial number to assign (default is 1)   */
 
155
 );
 
156
 
 
157
#define HEAP_Copy(orig) HEAP_CopySerial(orig, 0, 0)
139
158
 
140
159
 
141
160
/* Detach heap (previously attached by HEAP_Attach).
142
161
 */
143
 
void HEAP_Detach(HEAP heap);
 
162
extern NCBI_XCONNECT_EXPORT void HEAP_Detach(HEAP heap);
144
163
 
145
164
 
146
165
/* Destroy heap (previously created by HEAP_Create).
147
166
 */
148
 
void HEAP_Destroy(HEAP heap);
 
167
extern NCBI_XCONNECT_EXPORT void HEAP_Destroy(HEAP heap);
 
168
 
 
169
 
 
170
/* Get base address of the heap.
 
171
 */
 
172
extern NCBI_XCONNECT_EXPORT void* HEAP_Base(const HEAP heap);
 
173
 
 
174
 
 
175
/* Get the extent of the heap.
 
176
 */
 
177
extern NCBI_XCONNECT_EXPORT TNCBI_Size HEAP_Size(const HEAP heap);
 
178
 
 
179
 
 
180
/* Get non-zero serial number of the heap.
 
181
 * Return 0 if HEAP is passed as 0, or the heap is not a copy but the original.
 
182
 */
 
183
extern NCBI_XCONNECT_EXPORT int HEAP_Serial(const HEAP heap);
149
184
 
150
185
 
151
186
#ifdef __cplusplus
152
187
} /* extern "C" */
153
188
#endif
154
189
 
155
 
#endif /* NCBI_HEAPMGR__H */
 
190
 
 
191
/* @} */
 
192
 
 
193
 
 
194
/*
 
195
 * --------------------------------------------------------------------------
 
196
 * $Log: ncbi_heapmgr.h,v $
 
197
 * Revision 6.20  2004/07/08 14:11:11  lavr
 
198
 * Fix few inline descriptions
 
199
 *
 
200
 * Revision 6.19  2003/09/23 21:00:53  lavr
 
201
 * +HEAP_AttachEx()
 
202
 *
 
203
 * Revision 6.18  2003/09/02 20:45:45  lavr
 
204
 * -<connect/connect_export.h> -- now included from <connect/ncbi_types.h>
 
205
 *
 
206
 * Revision 6.17  2003/08/28 21:09:37  lavr
 
207
 * Accept (and allocate) additional heap extent in HEAP_CopySerial()
 
208
 *
 
209
 * Revision 6.16  2003/08/25 14:50:10  lavr
 
210
 * Heap arena ptrs changed to be "void*";  expand routine to take user arg
 
211
 *
 
212
 * Revision 6.15  2003/07/31 17:53:43  lavr
 
213
 * +HEAP_Trim()
 
214
 *
 
215
 * Revision 6.14  2003/04/09 17:58:51  siyan
 
216
 * Added doxygen support
 
217
 *
 
218
 * Revision 6.13  2003/01/08 01:59:32  lavr
 
219
 * DLL-ize CONNECT library for MSVC (add NCBI_XCONNECT_EXPORT)
 
220
 *
 
221
 * Revision 6.12  2002/09/25 20:08:43  lavr
 
222
 * Added table to explain expand callback inputs and outputs
 
223
 *
 
224
 * Revision 6.11  2002/09/19 18:00:58  lavr
 
225
 * Header file guard macro changed; log moved to the end
 
226
 *
 
227
 * Revision 6.10  2002/04/13 06:33:22  lavr
 
228
 * +HEAP_Base(), +HEAP_Size(), +HEAP_Serial(), new HEAP_CopySerial()
 
229
 *
 
230
 * Revision 6.9  2001/07/03 20:23:46  lavr
 
231
 * Added function: HEAP_Copy()
 
232
 *
 
233
 * Revision 6.8  2001/06/19 20:16:19  lavr
 
234
 * Added #include <connect/ncbi_types.h>
 
235
 *
 
236
 * Revision 6.7  2001/06/19 19:09:35  lavr
 
237
 * Type change: size_t -> TNCBI_Size; time_t -> TNCBI_Time
 
238
 *
 
239
 * Revision 6.6  2000/10/05 21:25:45  lavr
 
240
 * ncbiconf.h removed
 
241
 *
 
242
 * Revision 6.5  2000/10/05 21:09:52  lavr
 
243
 * ncbiconf.h included
 
244
 *
 
245
 * Revision 6.4  2000/05/23 21:41:05  lavr
 
246
 * Alignment changed to 'double'
 
247
 *
 
248
 * Revision 6.3  2000/05/12 18:28:40  lavr
 
249
 * First working revision
 
250
 *
 
251
 * ==========================================================================
 
252
 */
 
253
 
 
254
#endif /* CONNECT___NCBI_HEAPMGR__H */