This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Use calloc (x, y) instead malloc (x * y).


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]