Your Donations help keep my Software going!
I'm on a short vacation and will be back soon.
I'm selling some Homebrew Game Dev Devices. Check it out.
Tracking
Description
tTracking.h Provides simple automatic memory leak tracking and memory sentinels. This functionality is enabled for debug and partial builds only, as it should not be required for final builds. Tracked memory is stored in an STL set, which has O(log n) search time, so any speed hit from memory tracking should be (typically) very small and unnoticeable.
Methods
void *operator new(size_t size, char *F, tUInt32 L); //single allocation void *operator new[](size_t size, char *F, tUInt32 L); //array allocation void operator delete(void *ptr); //single deletion void operator delete[](void *ptr); //array deletion //Helper macro #define new new(__FILE__, __LINE__)
These methods provide the exact functionality of C++ new and delete, with some additions:
- Calls to new automatically include file and line information, thanks to the macro, for easy tracking
- Memory which is not deleted will be asserted at program termination
- Memory which accidentally overwrites 4 bytes past the end of its bounds will alert the user on delete
- Memory allocation mismatches(single/array) will assert
All of this helps to ensure code stability and helps prevent against tiny memory errors that can potentially snowball out of control.
Even though there is improved functionality, there are a few things worth mentioning, see the notes below for more details.
Notes
- This class is singleton class that provides a global instance and starts automatically.
- malloc and free are not overridden; however, they typically should not be used in C++ applications anyway.
- Memory sentinels are not allocated for the left side of buffers, but if this feature is really required, it could be easily added.
- Due to the way new and delete are overloaded in LibTate, there is a high probability that delete(but not new) may be called before or after program_main by your compiler's runtime library; this shouldn't cause a problem though since the tracker would be inactive at that time. However this behavior might appear strange during debugging of an application, so its worth mentioning that it is pretty normal, all things considered.