In < >
(Rahul Gandhi) writes:
>Which one is more fast?
>malloc followed by memset
>or
>calloc
In principle, calloc could be implemented as malloc followed by memset.
However, it could skip the memset call if the allocated memory came
directly from the OS (rather than being "recycled"), because many OSs
clear themselves the memory they allocate to a program (for obvious
security reasons).
So, a calloc call need not be slower than a malloc plus a memset call,
but it could be faster. I was deliberately ignoring the cost of the
additional multiplication calloc has to perform (due to its interface).
However, this should NOT be the criterion for choosing one or another.
If your application needs zeroed memory, call calloc, otherwise call
malloc.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: