Should we check if memory allocations fail?

后端 未结 7 1910
温柔的废话
温柔的废话 2020-12-31 08:41

I\'ve seen a lot of code that checks for NULL pointers whenever an allocation is made. This makes the code verbose, and if it\'s not done consistently, only when the program

7条回答
  •  悲哀的现实
    2020-12-31 08:54

    but it is much more difficult to troubleshoot if you don't log where the malloc failed.

    failed to allocate memory in line XX is to prefer than just to crash.

提交回复
热议问题