UWord nrRef; /* nr reference to this pool allocator */
UWord elemSzB; /* element size */
UWord nPerPool; /* # elems per pool */
- void* (*alloc)(const HChar*, SizeT); /* pool allocator */
- const HChar* cc; /* pool allocator's cc */
- void (*free)(void*); /* pool allocator's free-er */
+ void* (*alloc_fn)(const HChar*, SizeT); /* pool allocator */
+ const HChar* cc; /* pool allocator's cost centre */
+ void (*free_fn)(void*); /* pool allocator's free-er */
/* XArray of void* (pointers to pools). The pools themselves.
Each element is a pointer to a block of size (elemSzB *
nPerPool) bytes. */
PoolAlloc* VG_(newPA) ( UWord elemSzB,
UWord nPerPool,
- void* (*alloc)(const HChar*, SizeT),
+ void* (*alloc_fn)(const HChar*, SizeT),
const HChar* cc,
void (*free_fn)(void*) )
{
vg_assert(0 == (elemSzB % sizeof(UWord)));
vg_assert(elemSzB >= sizeof(UWord));
vg_assert(nPerPool >= 100); /* let's say */
- vg_assert(alloc);
+ vg_assert(alloc_fn);
vg_assert(cc);
vg_assert(free_fn);
- pa = alloc(cc, sizeof(*pa));
- vg_assert(pa);
+ pa = alloc_fn(cc, sizeof(*pa));
VG_(memset)(pa, 0, sizeof(*pa));
pa->nrRef = 0;
pa->elemSzB = elemSzB;
pa->nPerPool = nPerPool;
pa->pools = NULL;
- pa->alloc = alloc;
+ pa->alloc_fn = alloc_fn;
pa->cc = cc;
- pa->free = free_fn;
- pa->pools = VG_(newXA)( alloc, cc, free_fn, sizeof(void*) );
+ pa->free_fn = free_fn;
+ pa->pools = VG_(newXA)( alloc_fn, cc, free_fn, sizeof(void*) );
pa->nextFree = NULL;
vg_assert(pa->pools);
return pa;
Word i;
vg_assert(pa->nrRef == 0);
for (i = 0; i < VG_(sizeXA) (pa->pools); i++)
- pa->free (*(UWord **)VG_(indexXA) ( pa->pools, i ));
+ pa->free_fn (*(UWord **)VG_(indexXA) ( pa->pools, i ));
VG_(deleteXA) (pa->pools);
- pa->free (pa);
+ pa->free_fn (pa);
}
/* The freelist is empty. Allocate a new pool and put all the new
UWord* pool;
vg_assert(pa);
vg_assert(pa->nextFree == NULL);
- pool = pa->alloc( pa->cc, pa->elemSzB * pa->nPerPool );
- vg_assert(pool);
+ pool = pa->alloc_fn( pa->cc, pa->elemSzB * pa->nPerPool );
/* extend the freelist through the new pool. Place the freelist
pointer in the first word of each element. That's why the
element size must be at least one word. */
typedef struct _PoolAlloc PoolAlloc;
/* Create new PoolAlloc, using given allocation and free function, and
- for elements of the specified size. Alloc fn must not fail (that
- is, if it returns it must have succeeded.) */
+ for elements of the specified size. alloc_fn must not return NULL (that
+ is, if it returns it must have succeeded.)
+ This function never returns NULL. */
extern PoolAlloc* VG_(newPA) ( UWord elemSzB,
UWord nPerPool,
void* (*alloc)(const HChar*, SizeT),
/* Free all memory associated with a PoolAlloc. */
extern void VG_(deletePA) ( PoolAlloc* pa);
-/* Allocates an element from pa. */
+/* Allocates an element from pa. The function never returns NULL. */
extern void* VG_(allocEltPA) ( PoolAlloc* pa);
/* Free element of pa. */