I\'ve read with interest the post C difference between malloc and calloc. I\'m using malloc in my code and would like to know what difference I\'ll have using calloc instead.
Your point stated in 3. seems to indicate a case or unnecessary initialization. That is pretty bad speed wise, not only the time spent doing it is wasted but a whole lot of cache eviction happened because of it.
Doing a memset()
or bzero()
(that are called by calloc()
anyway) is a good way to invalidate huge portion of your cache. Don't do it unless you are sure you won't overwrite everything yet can read parts of the buffer that will not have been written (as if 0 is an acceptable default value). If you write over everything anyway by all mean don't initialize your memory unnecessarily.
Unnecessary memory writing will not only ruin your app performance but also the performance of all applications sharing the same CPU with it.