[PATCH] Use calloc (x, y) instead malloc (x * y).
Rich Felker
dalias@aerifal.cx
Fri Oct 25 17:30:00 GMT 2013
On Fri, Oct 25, 2013 at 03:38:32PM +0000, Joseph S. Myers wrote:
> On Fri, 25 Oct 2013, Andreas Jaeger wrote:
>
> > What about adding a wrapper around malloc instead?
>
> Note that, for efficiency, in such an (inline / macro) wrapper you want to
> distinguish the argument counting the number of elements (not constant)
> and the argument counting the size of an element (almost always constant,
> so SIZE_MAX / size gets folded to a constant) - and make sure each call
> passes the arguments in the right order, which may not always be the order
> the existing multiplication is written in.
Couldn't you just use __builtin_constant_p to automatically choose
whichever one is constant?
On the other hand, if you want to minimize size rather than time,
skipping a macro and just using a function call would be better.
Rich
More information about the Libc-alpha
mailing list