Modifying fixed-size allocators

Suppose you have a special purpose allocator for cells, called AllocateCell, that first searches its own free list and then, if needed, calls malloc to allocate an additional block to hold one hundred cells. FreeCell puts the cell on its own free list.

Since this allocator exists solely for efficiency, the simplest way to modify it for use with Purify is to override the efficiency measure by turning AllocateCell and FreeCell into the malloc veneer category. You can do this by conditionally compiling the allocation code depending on whether or not the program is Purify'd.

struct Cell *AllocateCell() {
#ifdef PURIFY
    return (struct Cell *)malloc(sizeof(struct Cell));
#else
    ... original code for AllocateCell ...
#endif /* PURIFY */
}
void FreeCell(struct Cell* c) {
#ifdef PURIFY
    free((char*)c);
#else
        ... original code for FreeCell ...
#endif /* PURIFY */
}