Why malloc+memset is slower than calloc?

后端 未结 3 1692
迷失自我
迷失自我 2020-11-22 02:17

It\'s known that calloc is different than malloc in that it initializes the memory allocated. With calloc, the memory is set to zero.

3条回答
  •  臣服心动
    2020-11-22 03:04

    Because on many systems, in spare processing time, the OS goes around setting free memory to zero on its own and marking it safe for calloc(), so when you call calloc(), it may already have free, zeroed memory to give you.

提交回复
热议问题