Reputation: 5071
I know that while c++ ::operator new
and associated flavors can be replaced/overridden, malloc
(and calloc
etc) can not.
However, is there still some (possibly platform specific) way to achieve the same (for example replace all malloc
calls with an implementation that prints something to stdout on each allocation)? Using some linker magic maybe? In particular I want to replace the mallocs used by static libraries that I'm linking into my application (without altering those libraries code). I'm interested in solutions for windows, but if someone has a solution for another platform, that's certainly an interesting pointer as well.
Upvotes: 0
Views: 1596
Reputation: 15172
If using MSVC instead of using a different allocator I suggest that you take a look at the debug CRT's reporting options (this is where leak reports can be generated for example, using _CrtSetDbgFlag). You can also send the report text to a file using __CrtSetReportMode and _CrtSetReportFile.
The existing debug allocator is already very capable.
Upvotes: 0
Reputation: 114
Malloc can be overloaded or overridden. Check out this link to mi-malloc https://microsoft.github.io/mimalloc/overrides.html
Upvotes: 1