为什么我会重载operator new或operator delete?(Why would I overload operator new or operator delete? [duplicat

编程入门 行业动态 更新时间:2024-10-27 12:29:46
为什么我会重载operator new或operator delete?(Why would I overload operator new or operator delete? [duplicate])

可能重复: 有什么理由重载全局新建和删除?

在c ++中,你可以重载new / delete操作符,这样做有没有什么好处? 因为在调用operator new它的结果值被发送给构造函数,并在调用operator delete之前调用析构函数。

Possible Duplicate: Any reason to overload global new and delete?

In c++ you can overload new/ delete operators, are there any benefits in doing so? Since right after calling operator new its result value is sent to the constructor and right before calling operator delete, the destructor is called.

最满意答案

重载的目的是控制内存分配。 在某些情况下,您希望使用自己的分配器而不是标准分配器(例如,希望分配来自静态池而不是直接来自堆)。

The point of overloading is to control the memory allocation. In some cases you want to use your own allocators instead of the standard ones (for example, when you want allocations to be from static pools and not directly from the heap).

更多推荐

本文发布于:2023-04-27 23:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329624.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我会   operator   delete   overload   duplicate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!