且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

全局非抛出:: operator new和std :: malloc之间的区别

更新时间:2023-11-14 22:24:40

除语法和 free delete


  1. 您可以方便地替换 :: operator new ;

  2. malloc 带有 realloc ,而 new 没有等效项;

  3. new 具有 new_handler ,没有 malloc

  1. you can portably replace ::operator new;
  2. malloc comes with realloc, for which new has no equivalent;
  3. new has the concept of a new_handler, for which there is no malloc equivalent.

(替换 m alloc 打开可以蠕虫。可以做到,但不能移植,因为它需要链接程序的知识。)

(Replacing malloc opens up a can of worms. It can be done, but not portably, because it requires knowledge of the linker.)