Qingqing Zhou wrote:
> On a separate matter, can anyone please explain me how this piece of code
> works:
>
> /* no free elements. allocate another chunk of buckets */
> if (!element_alloc(hashp, HASHELEMENT_ALLOC_INCR))
> return NULL; /* out of memory */
>
> element_alloc() in fact uses MemoryContextAlloc() stuff.
Well, element_alloc() uses the hash table's alloc function pointer. In
theory, that could be malloc() or anything else, although I notice this
abstraction is not consistently maintained (e.g. dir_realloc assumes
pfree() is sufficient to free an allocation).
I think it would be a good idea to change dynahash.c to assume that the
hash table's allocation function will elog(ERROR) on out-of-memory, so
its return value will always be non-NULL. This would allow for a bunch
of code to be simplified.
-Neil