Slashdot Mirror


Memory Checker Tools For C++?

An anonymous reader writes "These newfangled memory-managed languages like Java and C# leave an old C++ dev like me feeling like I am missing the love. Are there any good C++ tools out there that do really good memory validation and heap checking? I have used BoundsChecker but I was looking for something a little faster. For my problem I happen to need something that will work on Windows XP 64. It's a legacy app so I can't just use Boosts' uber nifty shared_ptr. Thanks for any ideas."

9 of 398 comments (clear)

  1. um by Anonymous Coward · · Score: 5, Informative

    boost::shared_ptr is not a memory checker, it's a reference-counted smart pointer, and works fine in legacy apps (such as compiled under VC++ 6).

  2. Re:two points by Anonymous Coward · · Score: 5, Informative

    Boehm's garbage collector is used in Inkscape -- and they did gradually introduce its use, so you can start using it for some things and gradually extend the usage.

    Boudewijn

  3. STLPort by kazade84 · · Score: 4, Informative

    I know this isn't exactly what the article is looking for. But, if you are using the STL (which you SHOULD be!) you may be interested to know that the STLPort STL implementation includes a debug mode which contains loads of error checking to make sure you aren't misusing STL.

    1. Re:STLPort by Chris_Jefferson · · Score: 4, Informative

      Actually, yes they do. In g++ use " -D_GLIBCXX_DEBUG ", in VC++ enable debugging. You'll get all these errors and more. I don't understand why everyone seems to know this part of stlport and don't realise other librarys have it as well.

      --
      Combination - fun iPhone puzzling
  4. Re:two points by Anonymous Coward · · Score: 4, Informative

    gcc 4.2 includes a good part of tr1 as was released (late) a few weeks ago.

    shared_ptr is a blessing and a curse. It saves you from manually destructing objects held in a collecton (good) but too many developers use it for lifetime management (bad).

  5. You are looking for PageHeap by Photo_Nut · · Score: 4, Informative

    PageHeap is a debugging tool for Windows created by Microsoft. It does what you want.

    For more information look here:
    http://support.microsoft.com/kb/286470

  6. Valgrind by bms20 · · Score: 5, Informative

    Use valgrind : www.valgrind.org It is (in my opinion) the best tool available for this purpose. In fact, I develop C++ exclusively on linux first because of valgrind, then port to Win32 later. By the way, you're not missing out on anything special by not programming in Java or C#. Both of those languages are slow, and introduce their own language complexities. -bms20

  7. Re:I've used... by TapeCutter · · Score: 4, Informative

    If you use MS compilers the memory debug stuff is in crtdbg.h, IIRC it has been there in one form or another since V1.5 but for some reason seems too obscure for the average Windows programmer to find. ;)

    It is a very handy feature for finding leaks, buffer overflows, ect. The only other product I've used to find memory problems on recent incarnations of Windows is Purify. The MS solution is infinitely simpler because it's built into the environment and it's narrowly focused on memory problems. To state the obvious and in fairness to Purify, MSDev is infuriatingly fussy when it comes to building debug modules for IBM's Purify.

    --
    And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
  8. Re:two points by d00ber · · Score: 4, Informative

    Also, shared_ptr has been promoted to the draft standard C++-0x so you can use std::shared_ptr.

    You'll be able to use C++-0x in gcc-4.3 with a switch.

    I also heard that std::auto_ptr is being deprecated (not removed) I guess in favor of rvalue references.

    Finally, there is a motion to include garbage collection in the C++ language. This is sponsored by none other than Hans Boehm among others.

    I realize this doesn't help immediately.