This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: libiberty: Don't needlessly clear xmemdup allocated memory


On Sat, May 28, 2016 at 10:12:19PM -0400, DJ Delorie wrote:
> 
> Alan Modra <amodra@gmail.com> writes:
> > 	* xmemdup.c (xmemdup): Use xmalloc rather than xcalloc.
> 
> In glibc at least, calloc can be faster than memset if the kernel is
> pre-zero-ing pages.  Thus, in those cases, your change makes the code
> slower by adding an unneeded memset.  Have you considered these cases?

Actually, I didn't consider that..  I was looking at usage of xmemdup
in binutils, gdb and gcc, and noticed that a lot of the calls don't
need to clear any memory, and those that do only need to clear at most
two bytes.  ie. All uses have alloc_size <= copy_size + 2.

So in real-world usage of xmemdup, I think the possible gain of fresh
sbrk memory resulting in no internal calloc memset is minimal at best
and of course if calloc is reusing freed memory then it will
internally memset to zero.

-- 
Alan Modra
Australia Development Lab, IBM


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