calloc()
zero-initializes the buffer, while malloc()
leaves the memory uninitialized.
(calloc()
将初始化缓冲区,而malloc()
使内存未初始化。)
EDIT:
(编辑:)
Zeroing out the memory may take a little time, so you probably want to use malloc()
if that performance is an issue.
(将内存清零可能需要一些时间,因此如果性能问题,您可能希望使用malloc()
。)
If initializing the memory is more important, use calloc()
. (如果初始化内存更重要,请使用calloc()
。)
For example, calloc()
might save you a call to memset()
. (例如, calloc()
可能会保存对memset()
的调用。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…