4 ms·
Interestingly enough malloc(3) on Lucid Lynx box says: malloc() allocates size bytes and returns a pointer to the allocated memory. The mem
by lloeki 15y ago
Interestingly enough malloc(3) on Lucid Lynx box says:
malloc() allocates size bytes and returns a pointer to the allocated
memory. The memory is not cleared.
whereas Lion says nothing particular about it
So I wrote a quickie:
#include <stdlib.h>
#include <stdio.h>
int main() {
int m = 1024*1024; //1M
int t = 1024*m; //total count: here 1G
char *v = calloc(1, t*sizeof(char)); //total size: 1GB
for(int i=0; i<t; i++)
{
if (v[i] != 0)
{
printf("%016u @%x %x\n", i, v+i, v[i]);
}
else if (i % (t/10) == 0)
{
printf("%016u @%x\n", i ,v+i);
}
}
}
Ran multiple times with various sizes including big enough sizes (t) to statistically cover a good deal of physical RAM, and the trigger never triggers.
I notice though that on Mac OS X the program starts right on the spot, while there is always a constant delay on Lucid. Looks like one zeroes on demand (by chunks probably) whereas the other zeroes initially.
- petsos 15y agocalloc differs from malloc, as it clears the memory. From the Mac OS X man page: The calloc() function contiguously allocates enough space for count objects that are size bytes of memory each and returns a pointer to the allocated memory. The allocated memory is filled with bytes of value zero.
- lloeki 15y agoAh sorry, bad version copy/paste on my part. I actually used calloc at some point to compare behaviors in allocation time with malloc, but with malloc it still has zeros everywhere. Nice for security, but how would one proceed when really wanting pedal-to-the-metal performance?