In order to track our memory usage and display some runtime statistics to the user (in a performant way) I'm overriding global new/delete (with a #define in a header - adding that header on top of every source file where we need to allocate/deallocate memory is going to ensure we can track all allocations going on).
I have two questions at this point since it's a multi-platform C++ codebase:
- this is old code and some places still use
malloc
next tonew
. I think I also need to override global malloc/free/calloc/realloc, is that correct? - STL containers: we use them a lot (e.g.
std::vector
). If I include my re-#defining header at the top of every source file, do I still need to pass a custom allocator likestd::vector<int, my_allocator<int>>
? Or are the globally re-definednew/delete
enough? I think I still need the custom allocator but I'm not sure.