Reputation: 219
I would like to track memory to check leaks and checking memory consumation (peek and so on) by overloading new/delete.
However, I have noticed that sometimes one delete is called while there is no corresponding new (even on simple programs with few lines of code using boost), it looks like it is possible to obtain memory from another way (malloc ?) and that delete is happy to free it after. This leads me to problems because I need to store information (sizes) with allocation.
I have overloaded the following methods is there one function missing ? or is this a bug with my c++ compiler/boost version ?
void * operator new( size_t size );
void * operator new( size_t size, const std::nothrow_t& ) noexcept;
void * operator new[]( size_t size );
void * operator new[]( size_t size, const std::nothrow_t& ) noexcept;
void operator delete( void* ptr);
void operator delete[]( void* ptr);
void operator delete( void* ptr, const std::nothrow_t&) noexcept;
void operator delete[]( void* ptr, const std::nothrow_t&) noexcept;
I am running under windows and mingw-w64 gcc so I prefer to use a "code" solution rather than a specific tool solution ("valgrind is not available), also this will allow me to run the program almost normally.
Upvotes: 1
Views: 1752
Reputation: 2690
Dr Memory is excellent and free
It doesn't need to instrument the code and the code keeps almost to the same performance as without it. I've used it many times to find and fix leaks
Upvotes: 2
Reputation: 76386
The Microsoft standard library sometimes uses the internal allocation functions directly rather than going through the operators. And not always consistently. Some years ago I tried this, using DUMA, but gave up when the streams started failing for exactly the kind of problem you are seeing.
It is possible to get it working in your code only the way visual leak detector does it, but then it misses the interesting case.
However, recently I noticed that on Wine wiki they have a page listing a couple of alternatives to valgrind. From which I tried Dr.Memory and it is basically equivalent of the valgrind memcheck tool and works like charm on Windows.
Also, using tool is actually much simpler, because you just build normal debug build and run it under the tool. The leak detectors trying to override allocations are notoriously complex.
Upvotes: 2