zeroing out memory

后端 未结 12 2019
無奈伤痛
無奈伤痛 2021-01-31 09:52

gcc 4.4.4 C89

I am just wondering what most C programmers do when they want to zero out memory.

For example, I have a buffer of 1024 bytes. Sometimes I do this:<

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 10:16

    I also use memset(buffer, 0, sizeof(buffer));

    The risk of not using it is that there is no guarantee that the buffer you are using is completely empty, there might be garbage which may lead to unpredictable behavior.

    Always memset-ing to 0 after malloc, is a very good practice.

提交回复
热议问题