This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
calloc() implementation question
- From: Olivier Langlois <olivier at trillion01 dot com>
- To: libc-alpha at sourceware dot org
- Date: Thu, 12 Dec 2013 01:45:12 -0500
- Subject: calloc() implementation question
- Authentication-results: sourceware.org; auth=none
Hi,
Just by inspecting the code, there is something that I do not find
obvious.
nclears variable values distribution must have been analyzed and
everything must have been carefully balanced
if nclears is often <= 9 is it better to evaluate nclears up to 4 times
rather than unconditionally use memset() for any value of nclears?
if (nclears > 9)
MALLOC_ZERO(d, clearsize);
else {
*(d+0) = 0;
*(d+1) = 0;
*(d+2) = 0;
if (nclears > 4) {
*(d+3) = 0;
*(d+4) = 0;
if (nclears > 6) {
*(d+5) = 0;
*(d+6) = 0;
if (nclears > 8) {
*(d+7) = 0;
*(d+8) = 0;
}
}
}
}
Greetings,
Olivier