link-grammar-5.8.0/link-grammar/memory-pool.c
/**
 * Create a memory pool descriptor.
 * 1. If required, set the allocation size to a power of 2 of the element size.
 * 2. Save the given parameters in the pool descriptor, to be used by
 *    pool_alloc();
 * 3. Chain the pool descriptor to the given pool_list, so it can be
 *    automatically freed. [ Not implemented. ]
 */
Create a memory pool descriptor.
1. If required, set the allocation size to a power of 2 of the element size.
2. Save the given parameters in the pool descriptor, to be used by
pool_alloc();
3. Chain the pool descriptor to the given pool_list, so it can be
automatically freed. [ Not implemented.
Create a memory pool descriptor . 1 . If required set the allocation size to a power of 2 of the element size . 2 . Save the given parameters in the pool descriptor to be used by pool_alloc () ; 3 . Chain the pool descriptor to the given pool_list so it can be automatically freed . [ Not implemented .
Pool_desc *pool_new(const char *func, const char *name,
                    size_t num_elements, size_t element_size,
                    bool zero_out, bool align, bool exact)
{
	Pool_desc *mp = malloc(sizeof(Pool_desc));
	mp->func = func;
	mp->name = name;
	if (align)
	{
		mp->element_size = align_size(element_size);
		mp->alignment = MAX(MIN_ALIGNMENT, mp->element_size);
		mp->alignment = MIN(MAX_ALIGNMENT, mp->alignment);
		mp->data_size = num_elements * mp->element_size;
		mp->block_size = ALIGN(mp->data_size + FLDSIZE_NEXT, mp->alignment);
	}
	else
	{
		mp->element_size = element_size;
		mp->alignment = MIN_ALIGNMENT;
		mp->data_size = num_elements * mp->element_size;
		mp->block_size = mp->data_size + FLDSIZE_NEXT;
	}
	mp->zero_out = zero_out;
#ifdef POOL_EXACT
	mp->exact = exact;
#endif 
	mp->alloc_next = NULL;
	mp->chain = NULL;
	mp->ring = NULL;
#ifdef POOL_FREE
	mp->free_list = NULL;
#endif 
	mp->curr_elements = 0;
	mp->num_elements = num_elements;
	lgdebug(+D_MEMPOOL, "%sElement size %zu, alignment %zu (pool '%s' created in %s())\n",
	        POOL_ALLOCATOR?"":"(Fake pool allocator) ",
	        mp->element_size, mp->alignment, mp->name, mp->func);
	return mp;
}
Pool_desc * pool_new ( const char * func , const char * name , size_t num_elements , size_t element_size , bool zero_out , bool align , bool exact ) { Pool_desc * mp = malloc ( sizeof ( Pool_desc ) ) ; mp -> func = func ; mp -> name = name ; if ( align ) { mp -> element_size = align_size ( element_size ) ; mp -> alignment = MAX ( MIN_ALIGNMENT , mp -> element_size ) ; mp -> alignment = MIN ( MAX_ALIGNMENT , mp -> alignment ) ; mp -> data_size = num_elements * mp -> element_size ; mp -> block_size = ALIGN ( mp -> data_size + FLDSIZE_NEXT , mp -> alignment ) ; } else { mp -> element_size = element_size ; mp -> alignment = MIN_ALIGNMENT ; mp -> data_size = num_elements * mp -> element_size ; mp -> block_size = mp -> data_size + FLDSIZE_NEXT ; } mp -> zero_out = zero_out ; #ifdef POOL_EXACT mp -> exact = exact ; #endif mp -> alloc_next = NULL ; mp -> chain = NULL ; mp -> ring = NULL ; #ifdef POOL_FREE mp -> free_list = NULL ; #endif mp -> curr_elements = 0 ; mp -> num_elements = num_elements ; lgdebug ( + D_MEMPOOL , " \n " , POOL_ALLOCATOR ? " " : " " , mp -> element_size , mp -> alignment , mp -> name , mp -> func ) ; return mp ; }
Create a memory pool descriptor.
Create a memory pool descriptor .
/* POOL_EXACT */ // POOL_FREE