(no title)
amavect | 11 months ago
I think my sane_realloc never freeing has much simpler behavior. As much as I hate the needless waste of 1 byte, if my code allocates thousands of 0-sized objects, I'd rather fix that before adding complexity to my sane_realloc.
With yours solving the 1 byte problem, it still interests me. We can simplify your code slightly.
#define SANE_REALLOC_EMPTY ((void *) -1)
void *sane_realloc(void *ptr, size_t size)
{
if (ptr == SANE_REALLOC_EMPTY) {
ptr = 0;
}
if (size == 0) {
free(ptr);
return SANE_REALLOC_EMPTY;
} else {
return realloc(ptr, size);
}
}
kazinator|11 months ago
If you want unique zero-sized objects, you can always simulate them with objects of size 1. The allocator API doesn't have to make that choice internally for you.
amavect|11 months ago