unitialized memory is all zeros...why not garbage instead?
Dag-Erling Smørgrav
des at des.no
Mon Jun 13 21:16:57 GMT 2005
Mike Hunter <mhunter at ack.berkeley.edu> writes:
> Is the pre-zeroing of malloc'd memory documented somewhere? By my reading
> of the malloc manapge...
malloc() does not pre-zero memory, but it hands you memory which has
been pre-zeroed by the kernel unless you've used it before. Your test
program makes only one malloc() call, so you get memory that has never
been used before.
> ...it seems like it's saying that malloc (as opposed to calloc) is NOT
> pre-zeroed. Is there a different document I should be reading?
No, but nowhere in the standard does it say that memory allocated with
malloc() must contain non-zero garbage. If that is what you want,
though, read the TUNING section in the malloc(3) man page.
DES
--
Dag-Erling Smørgrav - des at des.no
More information about the freebsd-hackers
mailing list