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."

18 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).

    1. Re:um by trolltalk.com · · Score: 3, Informative

      "leave the ugly but solid code alone until necessary."

      If its ugly its not solid. Ugly code is hard to understand at first glance, and its easy to introduce an error. Or do you consider code that's easy to make a mistake with as actually being "maintainable"?

      If its ugly, there's probably a non-ugly way to do the same thing that's better, more efficient, AND more maintainable.

      Remember, 90% of the investment in code is in the ongoing maintenance. Having to "relearn" all the "cute little hacks" that make that ugly POS code work, every time you have to change something, is a waste of resources. That ugly code is usually a monument to the "there's not enough time to do it right, but there's always enough time to do it over ... and over ... and over" and "ship it now - fix it later."

      I've written enough ugly code to know that if its ugly, I'm not approaching the problem properly.

  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

    1. Re:Valgrind by HRogge · · Score: 3, Informative

      If you still think Java/C# are slow, especially in terms of memory management you might want to read this:
      http://www.ibm.com/developerworks/java/library/j-j tp09275.html

    2. Re:Valgrind by Rogerborg · · Score: 3, Informative

      Agreed. I am not a fan of Linux development environments, but there really is nothing like Valgrind available for Windows, so run as much of your code as possible through Valgrind on Linux. I'd say that it is worth the effort, even if you have no intention of supporting a Linux distribution.

      --
      If you were blocking sigs, you wouldn't have to read this.
  7. Re:Fluid Studio's Memory Manager (MMGR) by Rezonant · · Score: 3, Informative

    It's true that MMGR is single thread only, and if your program allocates and frees memory on multiple threads you should choose another alternative. However, many many programs only allocate and free memory on one thread, and for those MMGR is simple to use and is pretty damn good at finding leaks, overruns and similar problems.

  8. 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.
  9. I must agree - Purify is it. by Anonymous Coward · · Score: 3, Informative

    I used to select tools for my team. For UNIX, I selected Purify and for Windows, BoundsChecker. After a few days with BoundsSlacker, **all** and I mean every one of my team was asking for Purify for Windows licenses. 17 licenses later and our code crashes have dropped byat least 90%.

    Yes, it isn't cheap. Just do it. You'll thank me.

    The productivity increase alone will make it worthwhile for management.

  10. Detailed article on memory usage by Tronster · · Score: 3, Informative

    Last week on Gamasutra was a good article on memory leak detection, and how to role your own tool:

    "Monitoring Your PC's Memory Usage For Game Development"

    While the title says it's for game development, I found that the meat of the article applies to any windows developer.

  11. Memory Validator by sdt · · Score: 3, Informative

    Have a look at memory validator. I don't know if it supports 64 bit applications, but it has a great list of features and is the only decent memory validation tool I've ever seen on Windows.

  12. 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.

  13. Use a testing framework by Heir+Of+The+Mess · · Score: 3, Informative

    Use a testing framework like Parasoft's CPP stuff http://www.parasoft.com/jsp/products/home.jsp?prod uct=CppTest

    --
    Australian running a company that does C# / C++ / Java / SQL / Python / Mathematica
  14. Re:two points by d00ber · · Score: 3, Informative

    My understanding is that it will be opt-in. I think manual management will be the default.

    They don't want to remove the old ways (including malloc/free). And they don't want to penalize people who don't use garbage collection. In other words, if you don't want to use garbage collection you won't be paying for it in code size/runtime.

    But for them that do... It might be nice to offer it.