可能重复: 有什么理由重载全局新建和删除?
在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).
更多推荐
发布评论