2323 * - SH_DEFINE - if defined function definitions are generated
2424 * - SH_SCOPE - in which scope (e.g. extern, static inline) do function
2525 * declarations reside
26+ * - SH_RAW_ALLOCATOR - if defined, memory contexts are not used; instead,
27+ * use this to allocate bytes
2628 * - SH_USE_NONDEFAULT_ALLOCATOR - if defined no element allocator functions
2729 * are defined, so you can supply your own
2830 * The following parameters are only relevant when SH_DEFINE is defined:
@@ -121,8 +123,10 @@ typedef struct SH_TYPE
121123 /* hash buckets */
122124 SH_ELEMENT_TYPE * data ;
123125
126+ #ifndef SH_RAW_ALLOCATOR
124127 /* memory context to use for allocations */
125128 MemoryContext ctx ;
129+ #endif
126130
127131 /* user defined data, useful for callbacks */
128132 void * private_data ;
@@ -142,8 +146,12 @@ typedef struct SH_ITERATOR
142146} SH_ITERATOR ;
143147
144148/* externally visible function prototypes */
149+ #ifdef SH_RAW_ALLOCATOR
150+ SH_SCOPE SH_TYPE * SH_CREATE (uint32 nelements , void * private_data );
151+ #else
145152SH_SCOPE SH_TYPE * SH_CREATE (MemoryContext ctx , uint32 nelements ,
146153 void * private_data );
154+ #endif
147155SH_SCOPE void SH_DESTROY (SH_TYPE * tb );
148156SH_SCOPE void SH_RESET (SH_TYPE * tb );
149157SH_SCOPE void SH_GROW (SH_TYPE * tb , uint32 newsize );
@@ -165,7 +173,9 @@ SH_SCOPE void SH_STAT(SH_TYPE * tb);
165173/* generate implementation of the hash table */
166174#ifdef SH_DEFINE
167175
176+ #ifndef SH_RAW_ALLOCATOR
168177#include "utils/memutils.h"
178+ #endif
169179
170180/* max data array size,we allow up to PG_UINT32_MAX buckets, including 0 */
171181#define SH_MAX_SIZE (((uint64) PG_UINT32_MAX) + 1)
@@ -328,8 +338,12 @@ static inline void SH_FREE(SH_TYPE * type, void *pointer);
328338static inline void *
329339SH_ALLOCATE (SH_TYPE * type , Size size )
330340{
341+ #ifdef SH_RAW_ALLOCATOR
342+ return SH_RAW_ALLOCATOR (size );
343+ #else
331344 return MemoryContextAllocExtended (type -> ctx , size ,
332345 MCXT_ALLOC_HUGE | MCXT_ALLOC_ZERO );
346+ #endif
333347}
334348
335349/* default memory free function */
@@ -350,14 +364,23 @@ SH_FREE(SH_TYPE * type, void *pointer)
350364 * Memory other than for the array of elements will still be allocated from
351365 * the passed-in context.
352366 */
367+ #ifdef SH_RAW_ALLOCATOR
368+ SH_SCOPE SH_TYPE *
369+ SH_CREATE (uint32 nelements , void * private_data )
370+ #else
353371SH_SCOPE SH_TYPE *
354372SH_CREATE (MemoryContext ctx , uint32 nelements , void * private_data )
373+ #endif
355374{
356375 SH_TYPE * tb ;
357376 uint64 size ;
358377
378+ #ifdef SH_RAW_ALLOCATOR
379+ tb = SH_RAW_ALLOCATOR (sizeof (SH_TYPE ));
380+ #else
359381 tb = MemoryContextAllocZero (ctx , sizeof (SH_TYPE ));
360382 tb -> ctx = ctx ;
383+ #endif
361384 tb -> private_data = private_data ;
362385
363386 /* increase nelements by fillfactor, want to store nelements elements */
0 commit comments