Should I override new / delete statements in my C ++ WIn32 applications

I know that Microsoft itself recommended overriding the new operator with calls to HeapCreate () and HeapAlloc (), but that was a long time ago. See KB139638 for more details.

Will I still benefit from overriding new / delete on Win32? What would be the recommended implementation?

TIA.

+4
source share
4 answers

The article says that you can do this, and not what you need. The code in it is so poorly written that it is not funny, and it is not thread safe. In general, the implementation provided by the new and the remote will work well for all common programming needs. You should only consider re-implementing them if you have identified a specific problem that such reintegration could solve.

+6
source

If you are not doing an intensive memory program (in which it would be more efficient to overload distributors in certain places anyway), the main advantage of overloading new and remote operators would be to track allocations and debug releases for debugging and profiling.

+3
source

In most cases, overloading the global new/delete is a bad idea (TM).

Class-level memory management (via overload) should only be used if necessary. Profile your application and see if there is a bottleneck with allocation / deallocation from the heap. In addition, things get complicated if your class can / will be obtained later (adds an extra load on the developer, since new/delete are static members).

Try switching to a dispenser (with strategies so you can verify what works best for your needs), similar to what STL does.

+1
source

Do you have a reason to do this? Not? Do not do it then; the chances of not making life extremely painful for yourself are subtle.

Do you have an application that you have profiled and determined that highlighting / releasing something is a bottleneck? Because until you do this, I would not worry about it.

This repeats premature wholesale :-)

+1
source

Source: https://habr.com/ru/post/1300408/


All Articles