Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4899504

Browse files
committed
simplehash: Allow use of simplehash without MemoryContext.
If the SH_RAW_ALLOCATOR is defined, it will be used to allocate bytesfor the hash table, and no dependencies on MemoryContext will exist.This means, in particular, that the SH_CREATE function will not takea MemoryContext argument.Patch by me, reviewed by Andres Freund.Discussion:http://postgr.es/m/CA+Tgmob8oyh02NrZW=xCScB+5GyJ-jVowE3+TWTUmPF=FsGWTA@mail.gmail.com
1 parentb1cc572 commit4899504

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎src/include/lib/simplehash.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
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+
#ifndefSH_RAW_ALLOCATOR
124127
/* memory context to use for allocations */
125128
MemoryContextctx;
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+
#ifdefSH_RAW_ALLOCATOR
150+
SH_SCOPESH_TYPE*SH_CREATE(uint32nelements,void*private_data);
151+
#else
145152
SH_SCOPESH_TYPE*SH_CREATE(MemoryContextctx,uint32nelements,
146153
void*private_data);
154+
#endif
147155
SH_SCOPEvoidSH_DESTROY(SH_TYPE*tb);
148156
SH_SCOPEvoidSH_RESET(SH_TYPE*tb);
149157
SH_SCOPEvoidSH_GROW(SH_TYPE*tb,uint32newsize);
@@ -165,7 +173,9 @@ SH_SCOPE void SH_STAT(SH_TYPE * tb);
165173
/* generate implementation of the hash table */
166174
#ifdefSH_DEFINE
167175

176+
#ifndefSH_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
#defineSH_MAX_SIZE (((uint64) PG_UINT32_MAX) + 1)
@@ -328,8 +338,12 @@ static inline void SH_FREE(SH_TYPE * type, void *pointer);
328338
staticinlinevoid*
329339
SH_ALLOCATE(SH_TYPE*type,Sizesize)
330340
{
341+
#ifdefSH_RAW_ALLOCATOR
342+
returnSH_RAW_ALLOCATOR(size);
343+
#else
331344
returnMemoryContextAllocExtended(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+
#ifdefSH_RAW_ALLOCATOR
368+
SH_SCOPESH_TYPE*
369+
SH_CREATE(uint32nelements,void*private_data)
370+
#else
353371
SH_SCOPESH_TYPE*
354372
SH_CREATE(MemoryContextctx,uint32nelements,void*private_data)
373+
#endif
355374
{
356375
SH_TYPE*tb;
357376
uint64size;
358377

378+
#ifdefSH_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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp