1.c++ 标准 new 失败是抛出异常的,Visual C++ 6.0中返回一个NULL指针.

使用new(std::nothrow)可以保证失败时返回NULL;

因此完全可以 #define new new(std::nothrow) .

2.使用 malloc/calloc 等分配内存的函数时,一定要检查其返回值是否为“空指针”,返回空指针表示申请内存失败。

eg:

#define new new(std::nothrow)

char
*p = new char[4]; if(p != NULL) { strcpy(p, "hi"); }

3.申请内存失败的原因:程序用完了所有的可用内存.

相关文章:

  • 2021-10-17
  • 2022-01-16
  • 2022-03-10
  • 2021-06-24
  • 2021-11-05
  • 2021-10-08
猜你喜欢
  • 2021-07-02
  • 2022-03-07
  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2021-11-26
  • 2021-10-29
相关资源
相似解决方案