3 ms·
> Why can't I have a malloc() that does lazy copy-on-write for large arrays reallocarray(3) (though fundamentally that's what malloc does as well, it just does
by masklinn 10y ago
> Why can't I have a malloc() that does lazy copy-on-write for large arrays
reallocarray(3) (though fundamentally that's what malloc does as well, it just doesn't do overflow checking)
> why can't I have an error checking malloc()
reallocarray(3) (because malloc doesn't get the information, it gets a single size rather than a count and a per-object size)
> why can't I have a calloc() that allocates the memory up front and doesn't zero it out?
reallocarray(3)
> Sounds like what you want to do practically is basically just make your malloc() wrap a calloc() with size 1, and stop explicitly memset()ing.
If you're going to memset(0) it there's no reason to use malloc() ever, but it's very common to malloc() then fill the allocation directly, in which case the memsetting is a redundant cost.