23
23
* - SH_DEFINE - if defined function definitions are generated
24
24
* - SH_SCOPE - in which scope (e.g. extern, static inline) do function
25
25
* declarations reside
26
+ * - SH_RAW_ALLOCATOR - if defined, memory contexts are not used; instead,
27
+ * use this to allocate bytes
26
28
* - SH_USE_NONDEFAULT_ALLOCATOR - if defined no element allocator functions
27
29
* are defined, so you can supply your own
28
30
* The following parameters are only relevant when SH_DEFINE is defined:
@@ -121,8 +123,10 @@ typedef struct SH_TYPE
121
123
/* hash buckets */
122
124
SH_ELEMENT_TYPE * data ;
123
125
126
+ #ifndef SH_RAW_ALLOCATOR
124
127
/* memory context to use for allocations */
125
128
MemoryContext ctx ;
129
+ #endif
126
130
127
131
/* user defined data, useful for callbacks */
128
132
void * private_data ;
@@ -142,8 +146,12 @@ typedef struct SH_ITERATOR
142
146
} SH_ITERATOR ;
143
147
144
148
/* externally visible function prototypes */
149
+ #ifdef SH_RAW_ALLOCATOR
150
+ SH_SCOPE SH_TYPE * SH_CREATE (uint32 nelements , void * private_data );
151
+ #else
145
152
SH_SCOPE SH_TYPE * SH_CREATE (MemoryContext ctx , uint32 nelements ,
146
153
void * private_data );
154
+ #endif
147
155
SH_SCOPE void SH_DESTROY (SH_TYPE * tb );
148
156
SH_SCOPE void SH_RESET (SH_TYPE * tb );
149
157
SH_SCOPE void SH_GROW (SH_TYPE * tb , uint32 newsize );
@@ -165,7 +173,9 @@ SH_SCOPE void SH_STAT(SH_TYPE * tb);
165
173
/* generate implementation of the hash table */
166
174
#ifdef SH_DEFINE
167
175
176
+ #ifndef SH_RAW_ALLOCATOR
168
177
#include "utils/memutils.h"
178
+ #endif
169
179
170
180
/* max data array size,we allow up to PG_UINT32_MAX buckets, including 0 */
171
181
#define SH_MAX_SIZE (((uint64) PG_UINT32_MAX) + 1)
@@ -328,8 +338,12 @@ static inline void SH_FREE(SH_TYPE * type, void *pointer);
328
338
static inline void *
329
339
SH_ALLOCATE (SH_TYPE * type , Size size )
330
340
{
341
+ #ifdef SH_RAW_ALLOCATOR
342
+ return SH_RAW_ALLOCATOR (size );
343
+ #else
331
344
return MemoryContextAllocExtended (type -> ctx , size ,
332
345
MCXT_ALLOC_HUGE | MCXT_ALLOC_ZERO );
346
+ #endif
333
347
}
334
348
335
349
/* default memory free function */
@@ -350,14 +364,23 @@ SH_FREE(SH_TYPE * type, void *pointer)
350
364
* Memory other than for the array of elements will still be allocated from
351
365
* the passed-in context.
352
366
*/
367
+ #ifdef SH_RAW_ALLOCATOR
368
+ SH_SCOPE SH_TYPE *
369
+ SH_CREATE (uint32 nelements , void * private_data )
370
+ #else
353
371
SH_SCOPE SH_TYPE *
354
372
SH_CREATE (MemoryContext ctx , uint32 nelements , void * private_data )
373
+ #endif
355
374
{
356
375
SH_TYPE * tb ;
357
376
uint64 size ;
358
377
378
+ #ifdef SH_RAW_ALLOCATOR
379
+ tb = SH_RAW_ALLOCATOR (sizeof (SH_TYPE ));
380
+ #else
359
381
tb = MemoryContextAllocZero (ctx , sizeof (SH_TYPE ));
360
382
tb -> ctx = ctx ;
383
+ #endif
361
384
tb -> private_data = private_data ;
362
385
363
386
/* increase nelements by fillfactor, want to store nelements elements */
0 commit comments