4 ms·
Ah, my way of dealing with memory allocation failure is to write a xmalloc/xcalloc/xrealloc that exit on error. So the idea would be that the library users can
by camel-cdr 4y ago
Ah, my way of dealing with memory allocation failure is to write a xmalloc/xcalloc/xrealloc that exit on error. So the idea would be that the library users can just:
#unded malloc
#define malloc xmalloc
...
I suppose I could make this the default behavior, and make it overwritable.
- mtlmtlmtlmtl 4y agoDoesn't this break things like Valgrind?
- asveikau 4y agoFirstly, an xmalloc will call malloc and add error checks. So malloc is still called. But more fundamentally, Valgrind hooks into the allocator (and the program at large) much more deeply. You could write your own allocator (many people deploy something other than libc's) and it would still figure it out.