I have just learned about the C calloc() function the other day. Having read its description and how it differs from malloc (1, 2), I get the idea that, as a non-embedded programmer, I should always use calloc(). But is that really the case?
One reservation I have is the extra delay for accessing the calloc()-ed memory, but I also wonder if there are cases when switching from malloc() to calloc() will break the program in some more serious way.
P. S. The zero-initializing aspect of calloc() is quite clear to me. What I'm interested in learning about is the other difference between calloc() and malloc() - lazy memory allocation provided by calloc(). Please don't post an answer if you're going to focus purely on the memory initialization aspect.
It's all about what you want to do with the memory.
mallocreturns uninitialized (and possibly not even real yet) memory.callocreturn real, zero'ed memory. If you need it zero'ed, then yes,callocis your best option. If you don't, why pay for zero'ing with a latency hit when you don't need it?