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

398 comments

  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 RegularFry · · Score: 2, Informative

      It's an alternative to needing a memory checker, though, so it would provide an valid solution to the problem for a new application.

      --
      Reality is the ultimate Rorschach.
    2. Re:um by Shadowlion · · Score: 3, Insightful

      > and works fine in legacy apps

      Regarding legacy applications, I think the point was that he can't go back through the app and rewrite everything to use smart_ptr.

    3. Re:um by ObsessiveMathsFreak · · Score: 0

      Regarding legacy applications, I think the point was that he can't go back through the app and rewrite everything to use smart_ptr.

      But he should.
      --
      May the Maths Be with you!
    4. Re:um by Evanisincontrol · · Score: 3, Insightful

      I hope that was supposed to be sarcastic, otherwise you are the worst developer I've ever heard of. Rewriting an entire legacy application just to use shared pointers is downright stupid. He might as well just redesign the entire software and build it from the ground up... but then you're not "maintaining" anymore. You've completely redefined your job description.

    5. Re:um by peterpi · · Score: 1

      Volunteering to help? There's only 999,999,999 LOC still to go!

      Ctrl-f "*"

    6. Re:um by bhsurfer · · Score: 4, Insightful
      The first thing I was told by my boss when I got hired was "You're going to look at this app and want to rewrite it from scratch. Don't do it, that's not what we want you for." Software doesn't need to be pretty, you just make improvements as you can and leave the ugly but solid code alone until necessary. It's an extremely rare situation to have the luxury of a complete redesign/rewrite.

      I guess that's a long way of saying "I agree completely with what you just said."

      --
      Those are my principles, and if you don't like them... well, I have others.
      Groucho Marx
    7. Re:um by Anonymous Coward · · Score: 2, Interesting

      Application Verifier from MSFT is the best free tool you can get (just make sure you have good symbols, as with all run-time checkers!) - http://www.microsoft.com/technet/prodtechnol/windo ws/appcompatibility/appverifier.mspx

      Other runtime commercial tools - BoundsChecker, Purify, etc

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

    9. Re:um by Evanisincontrol · · Score: 1

      I agree. As many times as I hear the motto, "do it right the first time," I never see it practiced enough in the industry. I try to hold myself to that standard and it looks like you do too.

      However, which is more frequent: Your boss asking you to design a system from scratch, or your boss asking you to maintain/extend an existing piece of software? I'd say the latter accounts for a majority of programming work these days. To an executive making big decisions, the temptation to use a legacy system is just too powerful to resist in most cases. <sarcasm>Why waste money designing a new system if the current one works, right?</sarcasm> I find myself rarely ever having the chance to really sit down and build something that is both functional AND maintainable.

      That said, I refer back to my original point. When you're forced to work with what's already there... well, you just do it. It's not ideal, but as the GP started, "It's ugly but solid." Maybe it's a pain in the ass to work with, but for now, it works, and that's all that Mr. Boss Man cares about. (And he's signing your pay checks.)

    10. Re:um by bhsurfer · · Score: 3, Insightful
      I meant "ugly" in the sense of "Not the way I would have done it" rather than in a "Holy shit, what a freakin' mess! This guy should be bagging groceries, not writing software!" kind of way. I certainly do not think that clever tricks and mounds of complex spaghetti code that were designed by avalanche is maintainable, believe me.

      I also have (unfortunately) written enough ugly stuff that when I go back later I say "I can't believe I actually did something that stupid."

      You live, ideally you learn, and when you look at code you wrote 5 years ago you likely slap your forehead in embarrassment - that's how you know you're getting better. That, and when your coworkers aren't trying to slash their wrists when they get handed something you wrote...

      --
      Those are my principles, and if you don't like them... well, I have others.
      Groucho Marx
    11. Re:um by joto · · Score: 4, Insightful

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

      You are confusing two aspects here. Ugliness does limit maintainability. But it does not limit "solidness". "Solidness" would mean that the code actually works, and has a proven track record, such as being used in production for over 20 years. Code that has been in production for over 20 years is usually both solid and ugly.

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

      Or it could be a monument over "the world is a complex place, and if you change anything here, and it causes the program to fail in some weird special case, your company is going to loose umpteen zillion dollars". While the reality is probably somewhere in between, rewrites should still be avoided like the plague. However, if you really have taken the time to understand what some nasty bit of code does, there's nothing wrong about cleaning it up. But most of the time, the ugly code is there for a reason.

    12. Re:um by eean · · Score: 1

      These shared_ptr's (or at least the KDE equivalent, KSharedPtr) are actually really easy to use. You can use them exactly like normal pointers. It wouldn't be a huge deal to switch, most just changing declarations.

    13. Re:um by Anrego · · Score: 2, Informative

      Ugly code is really unavoidable. It's going to happen. While you should always try to write good, clean, maintainable code, circumstances can conspire against you. Project requirements can change half way through development with a timeline that doesn`t allow for going back and changing code properly. And of course there are always people who have ample time to write good code, but just don`t know how/don`t care.

      After having worked on what I could only describe as some of the ugliest code on the face of the earth (written by people who previously made a living writing throw away code for PhD types (the kind of code that you use to find an answer, then never use again)) I would say the _real_ problem that makes one want to just go hang themselves in the server room with some cat5 is lack of documentation.

      Nothing compounds poorly written code as much as poor (or non-existent over here) documentation. If you _have_ to hack code to make something work in a hurry... COMMENT THE CRAP OUT OF IT. Put a huge comment block, with asterisks and exclamation points and a link to the page in your projects documentation manager describing why you did it, what should be done down the road when time allows, and an apology note to the next guy who has to work on the code.

    14. Re:um by trolltalk.com · · Score: 1

      I agree that docs are mandatory; I've used doxygen and its variants, but I'm finding that stuffing everything into a wiki is better. Just create pages, do the [[feature]] or [[variable]] or [[function]] bit as you describe how the software *should* work, and then click on all the links and "fill in the pages".

      Good documentation can keep you from inadvertently introducing memory leaks, and a wiki is so easy to set up, and to edit. The "discussion" features are handy too, to help annotate the thoughts of everyone as something was being modified...

    15. Re:um by Evanisincontrol · · Score: 1

      Commenting is one of the most helpful types of documentation there is. (I would say UML diagrams can sometimes be even more useful, if made correctly)

      I see a lot of comments in the code I play with. Unfortunately, most people don't understand the true purpose of commenting code. They put comments about what a code is doing, which is completely useless. Example:

      //this increments tempVar by one
      tempVar = tempVar + 1;


      To anyone writing a program: For the love of everything you hold dear, please, do not comment on what code does; instead, comment on why you're doing it! I'm not an idiot. I can see what code is doing. I want to know what you were thinking when you wrote it.

    16. Re:um by Anonymous Coward · · Score: 0

      I agree. But I'd also add comments about what the code is supposed to do.

    17. Re:um by Anrego · · Score: 1

      I agree fully. Thats actually what we are doing now. We use Trac to manage our project (and it's documentation) and it has worked out fairly well. We tend to put comments in the code to document specific sections, and use Trac's wiki to further explain things/provide general overview documentation.

    18. Re:um by humblecoder · · Score: 1

      You obviously don't believe in the old adage "if it ain't broke, don't fix it." Code might _appear_ ugly because of all of the special cases that have been discovered and fixed over the code's lifetime. If you rewrite the code, you might forget (or not be aware of) some of those corner cases, and then you run the risk of ending up with an elegant program that doesn't work!

      That being said, you may reach a point where a rewrite is in order but you shouldn't go rewriting code just to satisfy your own personal aesthetic.

    19. Re:um by allanj · · Score: 1

      It is my experience with C/C++ code, that much of the ugliness comes from optimization. When code was written 20+ years ago, processors were not the powerhouses they are now. Lots of effort went into making sure that the system not only worked, but worked fast enough for people to care about the result by the time it arrived. To some extent, making code really fast tends to make it ugly.

      Now, we've got multi-core multi-GHz processors with multi-Gb of insanely fast memory. 95% of the time, we don't need to tweak the code for performance any longer. We may bemoan the dearth of fast optimized code (and sometimes I do just that), but in the vast majority of applications, it doesn't matter if we optimize more than a single or a few dozen function. Besides, compilers are getting so good at local optimizations for a single function that we get some of that for free - without the ugliness.

      --
      Black holes are where God divided by zero
    20. Re:um by trolltalk.com · · Score: 1

      Source code that handles "corner cases" silently (no comments, no "We do this because ...", no "case ERR_SOCKET_CLOSED_EARLY" or "if (data > MAX_DATA_LEN)") is not just ugly -its bad. Its a trap waiting to cause all sorts of problems, and should be fixed.

      At the very least, a "// Yes, it strinks ..." so that we know that whoever wrote it might have had a reason to do it that way as an exception, rather than "business as usual."

      An elegant program that doesn't work, you can at least hope to find out why. An ugly one that you've introduced a bug into - you might not even know you've created a bug until its been in the field for 6 months, since you probably also don't have any test harnesses (ugly code is harder to create stand-alone tests for).

    21. Re:um by Anonymous Coward · · Score: 0

      We've been battling this "ugly code" issue at work lately.

      One developer or another finds a block of code that clearly doesn't work. It never could have worked. It was obviously a copy/paste from the next block up, with the required edits to go against the new table and the new fields incompletely made.

      This code has been running our stores since 1989 or so.

      Do we "fix" it? What is going to happen when the code actually starts doing something? Nobody has complained about it not doing what it appears to be trying to do.

      Arrrrrrrrrrrrrrrrgh!

    22. Maybe it's a pain in the ass to work with, but for now, it works
      If you need to maintain it, then by definition it doesn't work.
      --
      Only three things are certain; death, taxes, and apocryphal quotations - Ben Franklin.
    23. Re:um by j-pimp · · Score: 1

      Maybe it's a pain in the ass to work with, but for now, it works
      If you need to maintain it, then by definition it doesn't work.

      My car works now, but it needs gas and oil ocassionally. The air and fuel filters will eventually totally clog up. The anti-freeze is only good for 1,000,000 miles if the radiator lasts that long.

      Also I'm thinking of adding an intake fan for more horsepower, and perhaps replacing the current audio system with something that can handle MP3s

      Granted, code does not break down. But the computers it runs on does. Sometimes the same old code that ran fine on NT 3.51 needs to be made to work on Vista.

      Sometimes a new feature needs to be added. The linux kernel 2.0 worked just fine. It probably will boot just fine on modern hardware, although only using one core of one CPU and 4 gigs of ram. Sometimes a bug is discovered.

      Sometimes code is so well written for such a small scope of purpose that it rarely gets altered. Larry Wall's patch program comes to mind. However, sometimes a program needs new features as its use cases are growing and its users constantly rething how they want to use it. This is the case with perl.

      --
      --- Justin Dearing http://www.justaprogrammer.net/ We're just programmers.
    24. Re:um by j-pimp · · Score: 1

      It is my experience with C/C++ code, that much of the ugliness comes from optimization. When code was written 20+ years ago, processors were not the powerhouses they are now. Lots of effort went into making sure that the system not only worked, but worked fast enough for people to care about the result by the time it arrived. To some extent, making code really fast tends to make it ugly.

      Many times you can contain the ugliness. For example, you can use macros and inline functions to avoid having a really large function. Or you could break the parts into sections with comments. You can also use comments to explain the ugliness. Sometimes a comment of "I don't know why this works" when you fix a bug in someone else's ugly code is a good thing to put in in case someone else has to fix the ugly code with your band aids.

      Also, there are more elegant ways to optimize these days. Many of the good optimizations are tucked into readily available libraries.

      --
      --- Justin Dearing http://www.justaprogrammer.net/ We're just programmers.
    25. I almost put something along the lines of "code never needs an oil change". I didn't because I thought it was over pedantic and stating the obvious. Sigh.

      My car works now, but it needs gas and oil ocassionally [...] air and fuel filters [...] Granted, code does not break down.
      But it would seem that analogies, if pushed too far, do.

      Sometimes a new feature needs to be added.
      If something needs to be added, then logically it doesn't work without it. Whether or not it worked for the situation at some time in the past is competely irrelevant.
      --
      Only three things are certain; death, taxes, and apocryphal quotations - Ben Franklin.
    26. Re:um by j-pimp · · Score: 1

      Sometimes a new feature needs to be added.
      If something needs to be added, then logically it doesn't work without it. Whether or not it worked for the situation at some time in the past is completely irrelevant.

      Actually that and the scope of the change versus the scope of the system is quite relevant. Lets say you have an operating system and the government changes the time zone rules. A small subset of the operating system needs to be updated. Hopefully its not a code change in this case, but it might be for an embedded system. The old code is not broken at this point, it is just designed to handle an old set of rules.

      Now if you want to make a business use argument for rewriting versus fixing existing software, whether the legacy system worked yesterday is irrelevant. However, whether it was used yesterday is quite relevant. Users are humans and humans don't like change. Your legacy system is sunk cost, but retraining your homo sapians will cost money.

      --
      --- Justin Dearing http://www.justaprogrammer.net/ We're just programmers.
  2. two points by sentientbrendan · · Score: 3, Interesting

    This isn't really an answer to your question, but it's on topic and there's some questions I wanted to get answered myself.

    First of all, shared_ptr is going into the standard library as part of TR1. Does anyone know when common development environments, i.e. GCC and MSVC, will start including TR1?

    Second, I believe that there are a number of garbage collectors available as libraries for C++. I've heard boehm's garbage collector mentioned numerous times. My question is, are any of these libraries any good? Are they really practical to use in real world applications? Do you have to modify all of your types to use it, or can primitive and stl types work with it?

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

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

    3. Re:two points by Anonymous Coward · · Score: 0

      Inkscape is hardly a good example of memory management in C(++).
      Its memory use is vastly inefficient compared to Illustrator (for example).

    4. Re:two points by Anonymous Coward · · Score: 0

      Are there any attempts at porting boost or likewise libs to a functional version with continuation passing style? Later a runtime GC could use reference counts and make up for unwarranted memory allocation... the single assignment facade can be maintained to a decent extent.. Just curious. I have no idea but iterators can be implemented as a some form of list generators I guess. things are looking pretty convoluted however. I guess someone could be bored and do it just for the heck of it ...

    5. Re:two points by shutdown+-p+now · · Score: 3, Interesting

      too many developers use it for lifetime management (bad).
      Why is it bad? Isn't the whole point of shared_ptr to automatically manage the lifetime of a shared resource?
    6. Re:two points by master_p · · Score: 2, Informative

      Boehm's gc is very very good...on par with Java's collector and others. The source needs cleaning up, and some configuration bugs to be ironed out, but it is very good.

      In order to use it, you just have to include 'gc.h' in your files, which replaces 'new' with 'gcnew' using macros. Alternatively, you can bypass the standard library and provide a replacement for 'malloc' and 'free', but I did not manage to do that (due to the configuration bugs mentioned above).

    7. Re:two points by Craig+Ringer · · Score: 3, Interesting

      gcc has included most of tr1, especially , since at least 4.1. I think it was in 4.0 as well.

      It's a pity there's no way to ensure compatibility between boost::shared_ptr and std::tr1::shared_ptr , nor a really attractive non-preprocessor-reliant mechanism to switch between them (since typedefs in C++ do not work on incomplete template types).

    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.

    9. Re:two points by julesh · · Score: 2, Informative

      Second, I believe that there are a number of garbage collectors available as libraries for C++. I've heard boehm's garbage collector mentioned numerous times. My question is, are any of these libraries any good? Are they really practical to use in real world applications? Do you have to modify all of your types to use it, or can primitive and stl types work with it?

      I've deployed Boehm GC in real world applications before now, and consider the quality of the collector pretty good. It isn't a real-time collector, but on a reasonably low-end computer (350MHz PII) running applications with average memory requirements (total ~50MB in objects of around 100 bytes - 2K in size) delay times were minimal (around 10ms, which I arranged to occur after event processing when it was found that no new event was waiting, hence was rarely detected by the user). You can use any type you want with it -- there are at least three different approaches:

      * Make your classes inherit from a 'gc' base class
      * Use a placement new operator (e.g. "new (GC) MyObject;" or "new (PointerFreeGC) char[16384];")
      * Use the provided 'malloc' replacement library to replace all dynamic memory allocations with a GC allocation.

      I chose to go the second route, because it gave me the most control. I had to spend a little time debugging problems caused by forgetting to include the (GC), but certainly less than I would have spent debugging undeleted objects had I not used the collector.

    10. Re:two points by spammacus · · Score: 1

      I'm using MSVC 2005 and TR1 is not available. However, it's actually not that hard to roll your own shared_ptr. Scott Meyers' excellent "More Effective C++" (which IMHO every C++ developer should know about) has an excellent discussion of this very topic.

    11. Re:two points by trolltalk.com · · Score: 2, Informative

      "Finally, there is a motion to include garbage collection in the C++ language. "

      Call me old-fashioned, but I hope that's one that they will throw in the garbage. Call it something else if you're going to have garbage collection as an integral part. As a set of libraries, or as a compiler-time switch, fine - but not as part of the core. That's not C++, that's D.

    12. Re:two points by PseudoQuant · · Score: 1
      "... but too many developers use it for lifetime management (bad)."

      Please elaborate! To my understanding, using smart_ptr's to manage resource lifetime (as an aid to implement RAII) is considered good usage and best practice. e.g. see point 13 from Sutter & Alexandrescu's C++ Coding Standards. Are you disagreeing, and if so why?

    13. Re:two points by Anonymous Coward · · Score: 0
      If you were "using boost::shared_ptr", couldn't you just start "using std::tr1::shared_ptr"? Of course, I think this goes to show why knee-jerk objections to copious "using" statements are probably a bad idea...

      Also, instead of using typedef's, I sometimes use inheritance. Something like this might work:

      template<typename T>
      class my_shared_ptr : public std::tr1::shared_ptr<T>
      {
      }
    14. Re:two points by Craig+Ringer · · Score: 1

      Good point regarding `using'. I'm a twit for not seeing that.

      As for copious `using' statements ... IMO it's a bad idea to:

      - Reference a name imported with `using' from another context or re-import it with another `using' statement. Some compilers handle this, some do not.
      - Use `using' in almost any case. This is one of the few I'd consider, and even then only very carefully.
      - Import whole namespaces rather than individual freqently used names, unless the namespace is reasonably small and designed for that use. I particularly dislike `using namespace std'.

      I do think people get too upset about `using' statements that are private to individual compilation units.

    15. Re:two points by stonecypher · · Score: 2, Informative

      GCC got TR1 support two weeks ago. MSVS got it two years ago. Look in stdext:: in MSVS2k5.

      --
      StoneCypher is Full of BS
    16. Re:two points by akeru · · Score: 2, Informative

      You can also use the Boehm garbage collector as a leak checker. Rather than collecting garbage, it reports on (and, I *think*, frees) memory that was 'forgotten' without being properly released.

      --

      Let's hope that there's intelligent life somewhere out in space 'Cause there's bugger-all down here on Earth.

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

    18. Re:two points by oblivion95 · · Score: 1

      Does anyone have experience with SWIG and shared_ptr? I'm wondering how difficult it is to get SWIG to parse a boost header file. And of course, all the shared_ptrs would have to be instantiated explicitly in the SWIG definition file.

    19. Re:two points by Anonymous+Brave+Guy · · Score: 4, Insightful

      It's not automatically bad, but using semi-automated memory management like this tends to reduce the emphasis on constructing things only when they're needed and destroying them immediately when you're done with them. This concern, known as "Java bloat syndrome" in honour of the language that first popularised it, can lead to major performance problems in applications that manipulate a lot of data, and is a favourite mistake made by the cult of "hardware is cheap, so optimisation doesn't matter".

      The thing is, this sort of care-free programming philosophy is natural in languages like Java, so languages like Java have had to learn from their early mistakes and adapt. There have been dramatic improvements in GC technology since those early days, and today there isn't the same degree of performance penalty associated with relying on GC to clear everything up.

      However, this sort of behind-the-scenes magic isn't really the "C++ way". You can do it, but tools like shared_ptr don't have the same level of sophistication as full-blown GC. Using them requires some care from programmers, and as the grandparent post said, this can lead to problems if the programmers come to rely on them more than they ought.

      FWIW, I'm not sure I'd have described things in quite such black-and-white terms as the GP, but I can see the underlying point and I think it's a valid one.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    20. Re:two points by Anonymous Coward · · Score: 0

      TR1 is already implemented in GCC. It's been there experimentally since 4.0 under
      C0XX s slated for the next version (4.3). It's already on SVN if you want look at it.

    21. Re:two points by Anonymous Coward · · Score: 0

      Boehm's GC is conservative, not precise, due to the nature of C/C++. This means that things that look like pointers (strings, other stuff) might lead to things being kept in the liveset and never be collected. Java GC are called "precise" because they know of the nature of the data and can always correctly determine whether something it's looking at is a pointer or not.

      Also, Boehm's GC will break when you do "clever" stuff like XOR-encoding prev/next pointer in a doubly-linked list (not that it matters a lot, but you need to be aware of it).

      That being said, it is a very nice and clever GC considering the context in which it has to work. You just need to be aware of its shortcomings.

    22. Re:two points by Anonymous Coward · · Score: 0

      Isn't the whole point of shared_ptr to automatically manage the lifetime of a shared resource? RAII (Resource allocation is initialization), of which shared_ptr is an instance, is a tool for controlling the correct deallocation of dynamically allocated resources in general.

      Garbage collection is a tool for controlling the deallocation of one specific such resource: memory. Memory is a resource with special characteristics that make it a special case.

      In particular, it may be ok for the deallocation of memory once held by a dynamically allocated object to be optimized (read: deferred indeterministically). Typically, this isn't true for other types of resources; e.g. you want to release a lock or mutex immediately when it is no longer needed.
    23. Re:two points by flyingfsck · · Score: 1

      Boehm's garbage collector is used in GCC. That is probably the toughest test it can possibly get. I have used it myself in projects too. It certainly makes life a lot easier and the resultant programs are rock solid.

      --
      Excuse me, but please get off my Pennisetum Clandestinum, eh!
    24. Re:two points by maxwell+demon · · Score: 1

      Boehm's garbage collector is used in GCC.

      AFAIK gcc uses its own homegrown GC (which heavily relies on annotations in the source). The Boehm GC is however used for gcj.
      --
      The Tao of math: The numbers you can count are not the real numbers.
    25. Re:two points by TheRaven64 · · Score: 1

      A compiler is a pretty poor test of a garbage collector. When you invoke GCC, it typically runs for a few seconds and then terminates. Something that short-lived can just leak memory and not care. This was actually a fairly common idiom with a lot of applications with this kind of lifecycle, since calls to free() are relatively expensive you can just get the OS to clean up the whole program's memory when it exits.

      --
      I am TheRaven on Soylent News
    26. Re:two points by tomk · · Score: 1

      On par with Java?! Don't be ridiculous.

      Boehm's gc is far better than nothing. But comparing a kludgy hack in a language with non-typed pointers, to a language and runtime designed from the ground up for garbage collection, is laughable.

      Come back when you understand heap compaction, generational garbage collection, and the difference between references (which are typesafe, tightly controlled, and known by the runtime) and pointers.

    27. Re:two points by dr2chase · · Score: 1

      "Laughable" is not an appropriate word here. The Boehm GC works astonishingly well, given the obstacles that it faces. The BIBOP scheme that it uses is roughly equivalent to multiple-sized-free lists, which generally works well for malloc/free memory allocation. If you wish to nasty words like "laughable", I seriously suggest that you go out and take some measurements with real applications to back them up. Java will do better, but the gap is unlikely to be large enough to justify the sneering tone of your post. And it is also possible to devise a conservative-compacting collector (look for patents by Joel Bartlett). (You may safely assume that I understand all the "come back when" items you list.)

    28. Re:two points by shutdown+-p+now · · Score: 3, Insightful

      In other words, programmers shouldn't use shared_ptr as if it were a replacement for GC. When it is worded thus, I can fully agree with that (and indeed, anyone who understands how reference counting works, will agree as well). The nice thing about shared_ptr is that, unlike GC, it is still fully deterministic, and so it properly preserves the "C++ spirit".

    29. Re:two points by master_p · · Score: 1

      You will be hard pressed to find any differences in performance in a Java app and a GC'd C++ app which uses Boehm's GC. I have done several tests and the difference in performance starts to show up only on really heavy load.

      Another surprising fact is that C++ with Microsoft's memory allocator is stupidly slow...a test that takes 500 ms with Doug Leas malloc takes 22 seconds with Microsoft's allocator!!!

    30. Re:two points by Anonymous Coward · · Score: 0

      When you invoke GCC, it typically runs for a few seconds and then terminates.
      Yeah, unless you are actually working on a real project instead of doing homework assignments for CS101.
    31. Re:two points by TheRaven64 · · Score: 2, Insightful

      Most real projects use a build system that invokes the compiler once for each file, and then the linker once at the end. While GCC may be run hundreds of times, each invocation only lasts for a few seconds. If your code is taking longer to compile, then you should possible consider structuring it better.

      --
      I am TheRaven on Soylent News
    32. Re:two points by MenTaLguY · · Score: 1

      I'd be inclined to agree, actually, though that has do with massive structs like SPStyle (ugh) and poorly written manual memory management (livarot) rather than the boehm collector.

      Generally the garbage-collection-enabled code has done fairly well, and where we switched to using the bohem collector it often allowed us to share data structures, where previously extra copies were made to avoid memory management issues.

      --

      DNA just wants to be free...
    33. Re:two points by MenTaLguY · · Score: 1

      Note, we had to build up a lot of our own infrastructure to enable a gradual transition (see all the src/gc-* files). At minimum, you a way to pin gc-managed objects which are referenced from the non-gc heap.

      Granted, that may not be an issue for some projects -- many can probably get away with using the boehm collector in malloc-replacement mode, where you just twiddle the build flags and you're done. But we have an awful lot of RGBA buffers allocated by libraries we don't necessarily control, which would look like giant arrays of bogus pointers if they were blindly allocated as non-atomic buffers, so we had to leave the default malloc in place, and begin using the boehm allocator explicitly here and there.

      --

      DNA just wants to be free...
    34. Re:two points by MenTaLguY · · Score: 1

      It doesn't need to be part of the core, but they do need to further define certain areas of the language to permit garbage collection to be implemented in an entirely reliable fashion. That's the main part Hans cares about.

      --

      DNA just wants to be free...
    35. Re:two points by Anonymous Coward · · Score: 0

      GCC 4.1.2 ships with TR1, obviously placed in the std::tr1 namespace. Boehm GC is nice, recommended by Stroustrup, and will probably become the standardized GC in C++0x (it will be optional to use)

  3. I've used... by grusin · · Score: 2, Funny

    Some time ago i was using valgrind, but afaik it does not run under windows. I think that MS Dev has some memory leak detection built in, but it is far behind valgrind. Besides, who codes stable stuff for windows? :)

    1. 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.
    2. Re:I've used... by Anonymous Coward · · Score: 1, Informative

      I use VLD instead, it gives much more useful info to trace memory leaks than the standard crtdbg.h stuff.... (i.e. a stack trace of where the memory was actually allocated)

      http://www.codeproject.com/tools/visualleakdetecto r.asp

    3. Re:I've used... by inviolet · · Score: 5, Funny

      Memory checkers? GARBAGE COLLECTORS?! Have you no HONOR?!

      We are KLINGON. We need no checkers. We need no garbage collectors. We need none of these weak HUMAN facilities. We write our CODE from the COMMAND LINE:

      > COPY CON DECAPITATOR.EXE
      [Alt+077] [ALT+090] . . .

      --
      FATMOUSE + YOU = FATMOUSE
    4. Re:I've used... by TapeCutter · · Score: 1

      Ummm...I've been using crtBreakAlloc for generating stack traces since V1.5. No offence to you or VLD but I did say that crtdbg is "obscure" to many programmers. ;)

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
    5. Re:I've used... by fuliginous · · Score: 1

      Idiot we are KLINGONS we don't use computers we enslave other races like Vulcans to do our computing and they come with a built in voice control!

    6. Re:I've used... by ivucica · · Score: 1

      Hmm, I think we need a "Qa'Pla qo'" sample ... :)

    7. Re:I've used... by walkdudes · · Score: 1

      Check ISA at IBM.

    8. Re:I've used... by dkf · · Score: 1

      Heh. I've done that in the past. I'd got a machine into a state where I couldn't access any real devices - all I had was a ramdisk preloaded with not very much more than the core of DOS - and needed an executable in a particular location so that I could get the system to the point where I could boot a Linux install disk (I don't want to remember more details, other than the fact that this was in 1992 or 1993). It turns out that it is easier to write a COM file by hand than an EXE, but it's still possible...

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
  4. Fluid Studio's Memory Manager (MMGR) by Rezonant · · Score: 5, Interesting

    Yep, Paul Nettle's little memory manager rocks. It WILL find leaks in your program. http://www.paulnettle.com/ (Yes, you have to navigate through a horrible flash site to get it, but it's worth it).

    1. Re:Fluid Studio's Memory Manager (MMGR) by Anonymous Coward · · Score: 1, Interesting

      It seems to be single-thread only?

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

    3. Re:Fluid Studio's Memory Manager (MMGR) by Anonymous Coward · · Score: 0

      glibc includes all this stuff and a bit more, though it's obviously of not much use if you are on windows. see mcheck and mallopt.

  5. valgrind, libgc by Anonymous Coward · · Score: 2, Informative

    Use valgrind. It's for Linux only, but what it does is invaluable for most of the tasks. I don't know of any other tool of such help.

    Note this is not 'memory management tool', but one to help you find and clean up the memory leaks. There is no way to do proper garbage collection using the STL's allocators, though there is a 'gc' library http://www.hpl.hp.com/personal/Hans_Boehm/gc/ which tends to do the job. Haven't used it, though projects like Mono http://www.mono-project.org/ use it extensively.

    1. Re:valgrind, libgc by Anonymous Coward · · Score: 0

      Use valgrind. It's for Linux only, but what it does is invaluable for most of the tasks. I don't know of any other tool of such help.

      And if the App is windows-only, you can even use wine with valgrind.

      Note this is not 'memory management tool', but one to help you find and clean up the memory leaks. There is no way to do proper garbage collection using the STL's allocators, though there is a 'gc' library http://www.hpl.hp.com/personal/Hans_Boehm/gc/ which tends to do the job. Haven't used it, though projects like Mono http://www.mono-project.org/ use it extensively.

      Boehm's GC is also used in gcj (GNU Compiler for Java).

    2. Re:valgrind, libgc by dusanv · · Score: 1

      Yes, it's not a memory management tool but it's still indispensable on Linux. Valgrind finds stuff no other checker could. They cannot port it to other platforms soon enough.

  6. Purify by Anonymous Coward · · Score: 2, Informative

    Purify works quite well. It is big and slow, and doens't play nicely with ACE_Tao stuff sometimes (tao do cleaver things that scare s purify sometimes)

    1. Re:Purify by priyank_bolia · · Score: 1

      I had tried GlowCode, it works with ACE_TAO, I guess and is very nice tool.

    2. Re:Purify by 0123456 · · Score: 2, Interesting

      Yeah, I haven't used Purify in a few years, but when I tried it out it seemed very effective and found some bugs that would have been hard to track down otherwise. We didn't use it in the end because, at least at that time, it didn't like us dynamically generating machine code... otherwise it was better than anything else we tried; for normal C and C++ code it should work well.

    3. Re:Purify by Anonymous Coward · · Score: 0

      Mostly agree.

      On HP/UX, we've had odd problems with purify making a signal() call return failure when it otherwise returned success, but otherwise it is definitely da bomb!

  7. Can't think... by Anonymous Coward · · Score: 0

    After seeing some of http://www.worsethanfailure.com/ OMGWTF C Calculator Contest submissions today, I do believe you could get some fine examples of what you're looking..

    *hides*

  8. valgrind and gc.h by Anonymous Coward · · Score: 1, Informative

    Use valgrind to find the bugs and Hans Boehm's GC to not have to fix them.

    If you didn't already know of such tools then go do some research; what you want probably already exists.

    1. Re:valgrind and gc.h by flyingfsck · · Score: 1

      "Use valgrind to find the bugs and Hans Boehm's GC to not have to fix them." Very well put! :) It is basically impossible to write a C++ program without memory problems. There are long dissertations linked from the Boehm site that explains why.

      --
      Excuse me, but please get off my Pennisetum Clandestinum, eh!
  9. 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: 1

      Everyone includes such a debug mode, including Visual C++ and g++. In my opinion both g++'s and visual C++'s are suprior to the one found in STLport. However, it won't really help you find memory leaks, only corruption from the standard containers.

      --
      Combination - fun iPhone puzzling
    2. Re:STLPort by kazade84 · · Score: 1

      I'm pretty sure VC++ and g++ don't do this

    3. 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:STLPort by kazade84 · · Score: 1

      Ahh, sorry my mistake. My information came from Scott Meyer's Effective STL. I guess STLPort just advertise it a little more than the others :)

    5. Re:STLPort by Chris_Jefferson · · Score: 1

      Thanks a lot! I bet that (very good) book is where everyone keeps getting this fact from. It's nice to know. It might have of course have been true when it came out that g++ and VC++ hadn't got such debug libraries yet, I'd trust Scott Meyer to check.

      --
      Combination - fun iPhone puzzling
    6. Re:STLPort by drerwk · · Score: 1

      use " -D_GLIBCXX_DEBUG " .... I don't understand why everyone seems to know this part of stlport and don't realise other librarys have it as well.

      First, thanks for pointing it out. I did not know about it either, and I try to read the docs. But also try to Google GLIBCXX_DEBUG. You will not get many pages, and I do not see any link to GLIBC or GCC docs that tell me all about its features. If you Google stlport the first link will tell you all you need to know. Here it is: http://gcc.gnu.org/onlinedocs/libstdc++/debug.html
      Ok, seems obvious now...
  10. Most tools I've tried are useless by DrXym · · Score: 3, Insightful
    I've played with Boundschecker, Purify (& Quantify) and Fortify. My experience of these tools is that they either take a painfully long time to run, throw up too many spurious warnings or crash outright after eating all available memory / disk space.

    They might be useful for small apps but if you have a massive app they are almost more trouble than they are worth.

    It's hard to say what you can do except foster safe coding practice and highlight the common pitfalls such as memory leaks, buffer overflows etc. Many compilers can help detect heap / memory overruns because the debug libs put guard bytes on the stack & heap that trigger exceptions when something bad happens. There are also 3rd party libs such as Boehm which help with memory leeak / garbage collection issues and dump stats. I'd say using STL & Boost is also a very good way of minimizing errors too simply because doing so avoids having to write your own implementations of arrays, strings etc. which are bound to be less stable.

    1. Re:Most tools I've tried are useless by cerberusss · · Score: 2, Interesting

      They might be useful for small apps but if you have a massive app they are almost more trouble than they are worth.
      I'm of the opinion that the larger the application, the harder it is to write. So my philosophy is to chop programs up in different processes. The fact that you're stating that the memory checkers are only useful for small apps, might be a sign that your app is too big.
      --
      8 of 13 people found this answer helpful. Did you?
    2. Re:Most tools I've tried are useless by gladish · · Score: 2, Insightful

      This is a result of the way that most people are developing code. They build some huge app and then finally realize that it doesn't work because it's riddled with defects and memory leaks. What should have been taking place is the creation of small units tests which were then run under some runtime analyzer like pruify. With that said, I've used purify, insure++, and valgrind. I found insure++ to be the best. I will admint that the code runs much more slowly but I was amazed at the stuff that it found. I've never used the windows version, but you can get it for windows with dev studio integration.

    3. Re:Most tools I've tried are useless by ShakaUVM · · Score: 1, Interesting

      >> foster safe coding practice

      Agreed. Most skilled coders I know don't write code that has memory leaks. Even simple things like making sure your source code looks symetrical, matching allocations with deallocations (of whatever flavor), etc., is usually enough to avoid any problems with memory. It's easy (easy!) to write loops that never overflow, though you wouldn't know it with the amazing number of overflow exploits that have been found over the years.

      However, it gets nasty when dealing with legacy code that is already leaking, or when you unfortunately get partnered with somebody that doesn't know how to practice safe coding techniques. In those cases, I guess these sorts of tools are useful.

    4. Re:Most tools I've tried are useless by tepples · · Score: 1

      So my philosophy is to chop programs up in different processes. I'd like to see details of how you would apply your approach. How would you propose that the program "Mozilla Firefox web browser" be chopped up into processes?
    5. Re:Most tools I've tried are useless by cerberusss · · Score: 1

      Hehheh you got me there, however I got from the parent that he was talking about a monolithic piece of business software. I.e. backend stuff. We're currently doing a project where we read measurement data from one or more instruments and functions are split up into processes. So we have one daemon for reading out one particular instrument, one process for the plotting backend, one for archiving data, et cetera.

      --
      8 of 13 people found this answer helpful. Did you?
    6. Re:Most tools I've tried are useless by peterpi · · Score: 2, Insightful

      I love this comment, from Bjarne Stroustrup's home page (href=http://www.research.att.com/~bs/bs_faq2.html #memory-leaks)

      Q) How do I deal with memory leaks?

      A) By writing code that doesn't have any. (goes on to advocate vector & string)

      And also: C++ Is my favorite garbage collected language because it generates so little garbage (http://www.research.att.com/~bs/bs_faq.html#reall y-say-that)

      Over the past 6 months or so, I've really made an effort to better my usage of C++ (using Effective C++, Effective STL and C++ Coding Standards). With a combination of STL, references, RAII, std::string and boost::shared_ptr, all of my memory, ownership & null-pointer problems just went away. I hardly ever actually write 'new' any more. The Java model of just leaking objects and hoping they'll get collected sooner or later seems horrible.

      But I'm not maintaining old code, so this is completely -1 Offtopic.

    7. Re:Most tools I've tried are useless by andy_t_roo · · Score: 1

      - GUI stuff
      - network communication stuff
      - parsing (and running, if needed) stuff (xml/javascript/dhtml/...)

      theres three relatively discrete components, which are (theoretically anyway) only connected via requests for data and replies - i'm sure that each of those could be broken down further (plausible independent subsets of 'GUI stuff' could include menus, action bars, the actual webpage)

    8. Re:Most tools I've tried are useless by dhasenan · · Score: 1

      Gecko, XUL, networking, interface at the top level.

      For testing, you can provide a dummy display and use local sockets for networking; that lets you test Gecko for memory usage (and also allows for automated unit testing). And you can provide a dummy renderer that just sends stuff in whatever format Gecko produces to test the display. And so forth.

      After that, you're left with any weirdness that results from putting these well-tested components together. Any remaining errors will probably be difficult to find, though.

      There are projects such as JUnit, NUnit, and RhinoMocks that help with this sort of thing.

    9. Re:Most tools I've tried are useless by FerretFrottage · · Score: 1

      "The Java model of just leaking objects and hoping they'll get collected sooner or later seems horrible."

      Well if you are leaking objects and they have hard references to them, then they won't be collected. Hence the word "leak". However, if one manages their objects correctly, the current generation of jvms perform quite well IMHO.

      --
      "Look Lois, the two symbols of the Republican Party: an elephant, and a fat white guy who is threatened by change."
    10. Re:Most tools I've tried are useless by Rogerborg · · Score: 2, Insightful
      > However, if one manages their objects correctly, the current generation of jvms perform quite well IMHO.

      If one manages their objects correctly, C/C++ perform quite well too.

      --
      If you were blocking sigs, you wouldn't have to read this.
    11. Re:Most tools I've tried are useless by Rogerborg · · Score: 1

      Fortify (in conjunction with Valgrind on our Linux platforms):

      Total Files: 11503
      Total Bytes: 118311913
      Total Lines: 3548892
      Total Symbols: 222890

      85 million units shipped, on a dozen different platforms, via at least that many OEMs.

      If Fortify isn't working for you, you're not using it right.

      --
      If you were blocking sigs, you wouldn't have to read this.
    12. Re:Most tools I've tried are useless by DrXym · · Score: 1
      If Fortify isn't working for you, you're not using it right.

      Fortify has exactly one button to push when integrated into Developer Studio. Push the button and it supposedly analyses your code. When we installed Fortify to examine our product, we pushed the button and watched the machine CPU go to 100% and stay there until all system memory was exhausted and it crashed several hours later. What part wasn't I doing right?

      To be fair Fortify 4.0 fixed the memory exhaustion crash but it still took Fortify an entire afteroon and night to analyse our product. It is intolerably slow and virtually impossible to use without dedicating a whole machine to get a single trace out of it. Our produce is large at a million lines but not uncommonly large.

    13. Re:Most tools I've tried are useless by peterpi · · Score: 4, Insightful

      I didn't explain it all that well. What I mean is; I love destructors.

      A good example of what I'm talking about is a std::ifstream versus a java.io.FileInputStream. If you make an ifstream on the stack, you can be absolutely certain that when it goes out of scope, the destructor will be called and the file closed. You can be certain that it will happen, and you can also be certain when it happens; at the very point it goes out of scope.

      With a heap based FileInputStream, you have no such gaurentee. You leak it, and you just hope that the finaliser gets called soon (if at all). I've had more than one occasion where I've been leaking FileInputStreams quicker than the garbage collector cares to clean them up, and sooner or later the OS says 'no' and you get an exception. And it's very difficult to reproduce, because it's all down to the whim of the garbage collector, and you always go slower when you're looking for a bug.

      Of course the answer to this is to say "Well you should Close() your input stream beforehand". But that's just as bad as saying "You should delete your heap based objects" in C++. It's that situation of having to manually shut down objects that seems old fashioned to me.

      Maybe there's a better way these days, I've been away from Java for a couple of years now.

      (I do enjoy coding in either language though!)

    14. Re:Most tools I've tried are useless by SparkyFlooner · · Score: 1, Insightful

      You don't let the garbage collector determine when shared resources get closed. You explicitly close it yourself when you're done with it. Closing a stream and deleting the object that manages it are two different things

    15. Re:Most tools I've tried are useless by peterpi · · Score: 1

      They share the characteristic of being things that you have to remember to do before you stop using an object. Otherwise, bad things happen.

      To put it another way, RAII is impossible in Java, as far as I understand it.

    16. Re:Most tools I've tried are useless by timeOday · · Score: 1

      Agreed. Most skilled coders I know don't write code that has memory leaks.
      If you're writing an app small enough for a single coder, and you have a skilled person to write it, then you don't have a problem. Where things get tricky is when different people's code has to work together, especially if memory management (or pointers) are in any way involved.

      I've used purify in the past and found it helpful, but now I start new projects in Java. Java programs have bugs too, but at least they aren't full of undefined behavior. It's a shame, since a well-crafted C++ app is a thing of beauty and runs great. But in a group effort there are just too many untraceable bugs.

    17. Re:Most tools I've tried are useless by tepples · · Score: 1

      - GUI stuff
      - network communication stuff
      - parsing (and running, if needed) stuff (xml/javascript/dhtml/...)

      theres three relatively discrete components, which are (theoretically anyway) only connected via requests for data and replies But how much overhead would the communication among processes incur?
    18. Re:Most tools I've tried are useless by nuzak · · Score: 1

      RAII is nice, but Java has try/finally and thus doesn't so much need RAII. It'd be nice if it had better syntax, but it works. Now go write "Java is not C++" a hundred times on the blackboard. No looping.

      --
      Done with slashdot, done with nerds, getting a life.
    19. Re:Most tools I've tried are useless by Tyler+Durden · · Score: 1

      Try/finally sucks, but C++ has RAII and thus doesn't so much need try/finally. It has better syntax, and it works. Now go write "C++ is not Java, thankfully" a hundred times on the blackboard. No looping. :P

      --
      Happy people make bad consumers.
    20. Re:Most tools I've tried are useless by Anonymous Coward · · Score: 0

      Java is not C++
      Java is not C++
      Java is not C++
      Java is not C++
      java.lang.OutOfMemoryException

    21. Re:Most tools I've tried are useless by nuzak · · Score: 1

      Gosh, repeating back what I say with the terms reversed, how original. Yes, you just learned that Java is not C++ and that through rigorous deduction from that fact, that C++ is not Java.

      --
      Done with slashdot, done with nerds, getting a life.
    22. Re:Most tools I've tried are useless by andy_t_roo · · Score: 1

      I would guess that the communication overhead would be quite dependent on design, but would be relatively large. This is the reason that it is 1 monolithic program, but my post was more concerned with it being a theoretical possibility, as compared to the great-GP who (in a somewhat snarky manner) used FF as an example of a program that *could not* be broken up.

      I wonder if it would be possible to design an inter-process communication scheme in which it would be practical to break a large program like FF down into 10 or so sub-threads?

    23. Re:Most tools I've tried are useless by Tyler+Durden · · Score: 1

      Uh, just a joke. How much effort do you put into being such a dick?

      --
      Happy people make bad consumers.
    24. Re:Most tools I've tried are useless by nuzak · · Score: 1

      Sorry... slashdot's getting to me again. For all the "funny" mods, it really drains my sense of humor. I think I'm going to do another one of my "bang keyboard randomly to change password" vacations again :-/

      --
      Done with slashdot, done with nerds, getting a life.
    25. Re:Most tools I've tried are useless by Rogerborg · · Score: 1
      --
      If you were blocking sigs, you wouldn't have to read this.
    26. Re:Most tools I've tried are useless by Tyler+Durden · · Score: 1

      Yeah, you know you're in trouble when you start taking Slashdot too seriously. Not that *I'd* do anything stupid like that, of course. Naaaaahhhhhhhh...

      --
      Happy people make bad consumers.
  11. Boost? Ugh by Viol8 · · Score: 3, Interesting

    Talk about a sledgehammer to crack a nut. Boost strikes me as the sort of library used by people who want to show off how up to date their skills are , not people who really need to write a program to get a job done. Its bloated , has a wierd syntax that differs from the C++ norm and doesn't solve any problem that isn't already solved or could be done quite easily by standard C++ anyway. What is its point except as intellectual masturbation by its authors? No this isn't a Troll, this is a post by someone who was forced to use Boost for a year and I loath it. Yeah , mod me down , whatever...

    1. Re:Boost? Ugh by pzs · · Score: 5, Interesting

      I would be inclined to agree with this. I used the Boost Graph Library for some research code a few years ago. It's been designed to be extremely generic, which although a good thing sometimes makes it pretty difficult to just start coding something without all the bells and whistles. For operations on graphs, such as walking through, you can use their specialised functions for doing things but it takes days and days to work out how to use them and I ended up just using regular loops because they were much easier to understand.

      Getting it to compile was a bit of a nightmare too. It has its own native compilation management tool that you have to download as well. What the hell is wrong with using make like everybody else? It also uses a very complex template hierarchy that produces terrifying error messages.

      I'm sure that once you become an expert, BGL is really powerful and efficient, but I found the learning curve too steep. I just want to get in and build a working prototype quickly so I can see what I'm doing, not spend hours wading through manuals and examples to build the simplest program.

      I'll be with the parent post and get modded a troll by boost developers.

      Peter

    2. Re:Boost? Ugh by bms20 · · Score: 1

      Agreed - in part. I have had good results using the the threading library, and spirit, but particularly poor ones with their serialization library (I ended up re-implementing it). -bms20

    3. Re:Boost? Ugh by Anonymous Coward · · Score: 1, Informative

      That's a pretty harsh comment. Would you mind please giving some examples?

      Personally, I find that

      shared_ptr f (new Foo); ... // don't need to worry about when 'delete f' happens!

      and also scoped_ptr are simple to use and very useful.

      As with a lot of things there can sometimes be a tradeoff between the slope of the learning curve and the expressive power that you get as a result. Yes, there are more than a couple of Boost libraries that are over my head and where I write "standard" code instead. But Boost is not all-or-nothing - you should just use the bits that you like.

    4. Re:Boost? Ugh by kazade84 · · Score: 2, Insightful

      If you wanna "get the job done" then boost is sometimes exactly what you need. I'm not saying that you should memorize the whole library but sometimes a boost library is available for what you want to do. I couldn't live without boost::lexical_cast, boost::shared_ptr, boost::tokenizer and boost::python is genius. You *could* write all of those things yourself but honestly, why?

      If you wanna code in C++ then you'd better get used to the "weird syntax" of templates and especially the boost libraries, they ARE the basis of most of the additions to the standard library in TR1 so they will become the "C++ norm"

    5. Re:Boost? Ugh by Viol8 · · Score: 4, Insightful

      "you'd better get used to the "weird syntax" of templates and especially the boost libraries"

      I'm used to templates syntax (though I think its ugly and Stroustrup could have done a lot better) but Boost makes it worse by overloading operators and then using them in ways never intended that produce syntax that a plain C++ wouldn't even recognise, never mind understand what its doing.eg the gratiutous overload of () for matrix ops where a simple function call would have been much cleaner and easier to follow.

    6. Re:Boost? Ugh by Big+Smirk · · Score: 1

      Yes,

      I have found that most of what I get out of boost is a foot print for the way the class should be written and then I end up re-writting the class.

      For example, shared_ptr is not thread safe. You may say, "so what?" but unless I'm writting a massive program using IOcompletion or select, I pretty much no when something is allocated and when it is no longer needed. shared_ptr does nothing. But, if multithreaded, when thing finish up in orders that I cannot (or don't want to) predict, shared ptr would be ideal.

      template <class T, LockMechanism L, Allocator A>

      class shared_ptr {.... After all, boost has threads now right? right?
      --
      TODO: create/find/steal funny sig.
    7. Re:Boost? Ugh by Anonymous Coward · · Score: 0, Insightful

      Overloading operators is exactly the norm in standard C++ it is one of the most ingrained principles
      with which C++ was designed. Creating DSEL (Domain Specific Embedded Languages) like boost::spirit (where you basically write EBNF syntax in C++ to generate parsers) was and is a key goal when C++ was developed.

      So you now don't know what an operator like does? So what, it does the what it is supposed to do in this context.
      This helps to really rise the abstraction level of the language to solve problems of the problem domain, in a very efficient way.

    8. Re:Boost? Ugh by oergiR · · Score: 2, Informative
      You are misinformed. You probably don't have any experience with Boost, nor do you get your facts right. Boost consists of different parts, and for using boost::shared_ptr you need only a couple of headers. There is even a tool that extracts the necessary bits for you.

      Its bloated , has a wierd syntax that differs from the C++ norm and doesn't solve any problem that isn't already solved or could be done quite easily by standard C++ anyway. boost::shared_ptr has been in standard library implementations for a couple of years now as std::tr1::shared_ptr. It will most likely be included in the next C++ standard. Apparently the C++ standard committee did think that shared_ptr solves problems that the old C++ standard does not.
    9. Re:Boost? Ugh by Pretor · · Score: 1
      You must be kidding. Have you actually tried to use boost for more than a second? You only have to use the parts of boost that you need. It's not that you have to link or include every boost library for you application. I've been using boost professionally for several years. And it really makes coding in C++ a lot nicer. Please note that you need a modern compiler like G++ > 3 or Visual C++ 2005. Otherwise you'll have to play with the compatible syntax which is horrible.

      Here are some of the parts that we use:

      • boost::smart_ptr
        This is probably the entry for a lot of the Boost users. Simple smart pointers that does the work most of the time. Create a RAII helper class or use LOKI Smart pointers if you have special cases that you cannot solve with boost::smart_ptr.

      • boost::python
        Easy to use and extend if you want to package you c++ library as a Python package. It does require a fair amount of CPU and Memory. But if you have an old/underpowered computer as a professional developer you ask your boss for a better computer or get a new job. In my personal opinion it's much nicer that SWIG and you get the added benefit of using the C++ compiler instead of a special pre-processor.

      • boost::signals
        Easy to implement the observer and the mvc patterns.

      • boost::bind and boost::function
        Handles a lot more cases than the standard template library binders and adapters (bind2nd, bin2st, mem_fun, ptr_fun and etc).

      • boost::threads
        Cross platform threading. We are using both Linux and Windows.


      As a side note I do prefer libsigc++ to the boost::signal and boost::bind. But this is an additional dependency that we don't bother with when we're already using boost.

    10. Re:Boost? Ugh by JonasG · · Score: 1

      Some parts are very useful. Smart pointers, bind, filesystem (we would have used the Windows API in my current project if I hadn't found it) and also string, which contains lots of things missing from C++'s standard string functions (like a split function). I find the mentioned parts of Boost to be quite easy to use too.

      During the project I'm currently working on we would also use a graph. I checked out Boost's graph library and we chose not use it but implement our own graph. I now partly regret this, however I'm not sure Boost's graph would have been easy enough to use.

    11. Re:Boost? Ugh by Anonymous Coward · · Score: 0

      IMHO shared_ptr is an acknowledge that Java got it right (there is no need for objects, references, pointers and smart pointers, one is enough).

      Yes, Java got it own problems ... a lot of them.

    12. Re:Boost? Ugh by Cyberax · · Score: 2, Informative

      You don't usually need to build anything to use BGL - it's mostly header-only library. It has only two small helper files.

      And Boost.Build is muuuuuch more powerful than makefiles. You can try to use Boost.Build v2 in your own projects - it's very very useful.

    13. Re:Boost? Ugh by Viol8 · · Score: 1

      "was and is a key goal when C++ was developed."

      Oh really? Well thats the first time I've heard of it. Provide a link.

      "So you now don't know what an operator like does? So what, it does the what it is supposed to do in this context."

      Well thats helpful when you're a maintenance programmer faced with 10,000 lines of code that could be doing anything and you have no idea what because the guy who wrote it thought it would be cool to overload every operator he could think off and to hell with readability and comprehension 2 years down the line.

      "This helps to really rise the abstraction level of the language to solve problems of the problem domain, in a very efficient way."

      Bullshit. Its no more efficient than function calling , its just a way for coders show off.

    14. Re:Boost? Ugh by Viol8 · · Score: 1

      "Apparently the C++ standard committee"

      Ah yes , the C++ commitee. The people who turned C++ from a learn OO version of C into the bloated mess we have today. Sorry , but they're hardly a name to drop in an argument to bolster your case.

    15. Re:Boost? Ugh by ardor · · Score: 1

      Correction: the people who gave C++ templates, which are a killer feature. Thanks to templates, I can do generic programming and metaprogramming in C++, which are orders of magnitude more powerful than OO only.

      No, Java generics are not the same.

      --
      This sig does not contain any SCO code.
    16. Re:Boost? Ugh by ardor · · Score: 1

      BS again. Overloading a + operator is just "showing off"? I suppose you like adding vector components manually, instead of doing v1 + v2? How about bigint classes, operator overloading is a bless there. Correct use of templates can significantly reduce the amount of written code and clarify it, as shown in the earlier vector example.

      --
      This sig does not contain any SCO code.
    17. Re:Boost? Ugh by rabidgnat · · Score: 2, Informative

      In 1.34, Boost made a Windows install tool that makes it much more easy to use. Just run the installer, put it in the directory you want, and change the Visual Studio settings to include $BOOST_ROOT. You could easily get going in 5 minutes

      By the way, if you're not developing for Boost and aren't using one of 8 or 9 libraries, you don't *have* to run their build system. Just pointing Visual Studio or GCC to $BOOST_ROOT is all you need to do. It sounds like taking 5 minutes to read the "getting started" page would have saved you a lot of grief ;)

    18. Re:Boost? Ugh by Viol8 · · Score: 0, Flamebait

      Do you actually write real programs or do you just play around with coding paradigms all day? You seem to like name dropping - RAil , LOKI, SWIG (whatever the hell that is) ,binders, adapters, observer , mvc patterns (oooh , patterns , theres a word no-nothings drool over) but can you actually code? Could you sit down and write for example a network server to do real time trading and failover without being surrounded by a mountain of books to give you all the latest buzzwords & TLAs to impress your boss with and blocks of code you don't really understand and you couldn't write yourself to use as lego bricks to build your slow, bloated app? I doubt it somehow.

      Sorry , but I get tired of people of your ilk. Perhaps I'm too old for coding , but when all it consists of is buzzword of the month and seeing the bloatware that gets dished up these days as "code" I do wonder about the general level of ability in the IT industry. It seems its gone the way of politics - all image , spin and buzzwords but little ability to get any decent work done.

    19. Re:Boost? Ugh by ardor · · Score: 1

      MVC and RAII are basics, not "fancy new toys". It is likely that you already know them, just not by this name. Happens to me often, too, I implement design patterns and don't know that this is actually pattern XYZ.

      --
      This sig does not contain any SCO code.
    20. Re:Boost? Ugh by dzorz · · Score: 1, Informative

      Boost is a collection of a lots of libraries and you can use only pieces that suite you. For example, shared_ptr has a very simple usage pattern and solves a problem that wasn't that easy to solve. It is already included in TR1. You really can't say that shared_ptr is bloated, too complicated or that it is a nightmare to compile - it only needs header files!
      I would also recommend checking scoped_ptr, boost::random, boost::threads, boost::date_time and boost::filesystem. I use them all extensively in a single library that has to compile on gcc (Mac & Linux), MSVC80 and (!) Borland C++.
      As for the complaints about the boost build system - bjam. I really have to disagree with you. You *don't* need to use it. Use it only to compile boost libraries, and then integrate them using whatever tool you want. I personally recommend cmake - it generates Xcode, MSVC, Borland projects or simple Makefiles among others... I use it to generate all of these.
      Yes, it generates awful error messages, but, one could argue that STL and template metaprogramming in general generate awful error messages. It is something that is deemed to be fixed in new C++ standard.
      I will agree with grandparent that some boost libraries are mental masturbation - boost::lambda comes to my mind :-) Some boost libraries rely on really ugly hacks (e.g. in boost::serialization - order of include files matters!!) and produce very bloated code, but you should judge it on a library per library basis.

    21. Re:Boost? Ugh by Viol8 · · Score: 0

      "which are orders of magnitude more powerful than OO only."

      In what way powerful? They save a few lines of code. Period. At the expense of readability in most cases. If you really believe templates increase the problem solving domain of the language then you obviously have little experience of real programming.

    22. Re:Boost? Ugh by ardor · · Score: 1

      Simple. Generic programming allows N+M work, whereas pure OO forces N*M. N being the number of algorithms, M the types. Translating to real code, the advantages of a generic vector container like the STL vector should be obvious, unless you feel inclined towards writing such a container for every type. This is true because generic programming identifies the properties of an object directly (for example, a + operator), and plain OO identifies types (thus ensuring that an object has certain properties).

      Template metaprogramming also allows policy-based design, which essentially introduces permutations. Context vs. Context for instance. This way, you can optionally add thread safety at compile-time. Impossible with pure OO, and very big timesaver. How about iterators? Impossible in OO at compile-time and without downcasts (thats what Java does). Generic find algorithm? MVC signals? (These are extremely handy for GUI toolkits) Or how about stuff like boost::bind?

      Without templates, C++ loses its real advantage.

      --
      This sig does not contain any SCO code.
    23. Re:Boost? Ugh by MikeTheMan · · Score: 2, Interesting

      I pretty much had the exact same experience. I tried to use the Boost Graph Library to create a visibility graph for a motion planning problem, and while it eventually did work, it was painful to get it working. At one point, I spent 3 hours (!!) trying to get the program to just compile. Errors were awful, kinda like STL errors but on steroids. In a standard-size terminal, each error took up about 8 lines.

      And they weren't helpful errors, mind you. Due to some template magic, something had broken, and instead of telling me what really happened, Boost (at some point during compilation) replaced a template with an actual class called boost::error_property_map_not_found. What followed was a slew of errors saying that boost::error_property_map_not_found did not support the + operation, or the - operation, or...you get the idea.

      The library seems plenty powerful. I think it would benefit from more examples, though. LOTS more examples.

    24. Re:Boost? Ugh by ardor · · Score: 1

      If v1 + v2 is not readable for you, I suggest you learn some math.
      The grep argument is valid, though I use egrep and a regexp in this case.
      Also, I suspect you also hate extremely hard to read associative container access like table["entry"] = value; right?

      --
      This sig does not contain any SCO code.
    25. Re:Boost? Ugh by maxwell+demon · · Score: 1

      IMHO shared_ptr is an acknowledge that Java got it right (there is no need for objects, references, pointers and smart pointers, one is enough).

      I disagree. Java doesn't have shared_ptr. Java has GC. If anything, shared_ptr is an acknowledge that raw pointers (as inherited from the low-level C language) are simply not the ideal tool for high level programming. Which doesn't say anything about if Java got it right, or if it got it wrong in just another way that C. Note that shared_ptr is not the only smart pointer, which is more of a hint that "one size fits all" doesn't really work (which again can be seen as an argument against the Java model).
      --
      The Tao of math: The numbers you can count are not the real numbers.
    26. Re:Boost? Ugh by ardor · · Score: 1

      Context vs. Context
      should be Context < SingleThreaded > vs. Context < MultiThreaded >

      --
      This sig does not contain any SCO code.
    27. Re:Boost? Ugh by Rakshasa+Taisab · · Score: 1, Interesting

      Erhmm... As I read the two parent comments, it's obvious you don't know _what_ boost really is.

      It's not primarily meant for production use, rather it is a _testbed_ for future improvements to the C++ standard library. Pretty much a place where they intentionally test the bounds of the C++ language and check what kind of features would make sense in the standard.

      --
      - These characters were randomly selected.
    28. Re:Boost? Ugh by Anonymous Coward · · Score: 0

      If v1 + v2 is not readable for you, I suggest you learn some math.
      I think I speak for many programmers when I say that math is a lot more readible if you spell out what you're doing. Of course, in this instance, we all know that you mean simple vector addition. But in the context of C++ programming, this isn't clear at all. Having a full function name (and real variable names instead of v1 and v2) would make it much more clear what is actually going on.
    29. Re:Boost? Ugh by maxwell+demon · · Score: 3, Insightful

      "I suppose you like adding vector components manually, instead of doing v1 + v2?"

      No , something like vectorAdd(v1,v2) would be a lot more readable and a damn site easier to grep for. Idiot. Then probably we should remove the operators for built-in types as well. After all, you could use functions like doubleAdd(a, b). As a bonus, you'd not get nasty surprises when mixing unsigned and signed integers. intGreater(a, n) would always give you the expected answer, even if a is negative and n is unsigned. If you'd want to compare in unsigned arithmetics, you'd use uintGreater(a, b) instead. And what dereferenePointer(p) does is self-evident, unlike *p. Also, removing all operators would greatly simplify the parser, because the only types of expressions it would have to parse would be constants, variables and function calls.

      But I just see you signed your post with "Idiot." Thus I guess I shouldn't have taken it seriously anyway. :-)
      --
      The Tao of math: The numbers you can count are not the real numbers.
    30. Re:Boost? Ugh by antime · · Score: 1

      So you now don't know what an operator like does? So what, it does the what it is supposed to do in this context.
      And people complain that Perl is a write-only language..
    31. Re:Boost? Ugh by jhol13 · · Score: 1

      The effect in Java is like every pointer (or object reference or whatever you want to call them) were shared_ptr (except better).

      The point I (the AC) was trying to make that HLLs do not necessarily need lot of different kind of "handles" to an object, one suffices.

      For example, you can have weak pointers in Java - except that they are 100% interchangeable with "normal" ones. In C++ smart pointers are not. So, IMHO the Java model actually does work better than C++ in many ways (not always, not in every respect, but most of the time).

    32. Re:Boost? Ugh by marnek · · Score: 2, Informative

      If I saw v1 + v2, how would I know if it's adding the numerical vectors v1 and v2 or appending v2 to the end of v1 ? What if v1 and v2 are not numerical? Or do you think people should just intuitively know that for numerical vectors the + operator means element-wise addition and otherwise it means concatenation?

    33. Re:Boost? Ugh by maxwell+demon · · Score: 1

      Well, that's actually the point of design patterns. Design patterns are not invented, they are discovered.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    34. Re:Boost? Ugh by kazade84 · · Score: 1

      I think the real question to ask is do you write real programs? That guy was just explaining to you why he uses boost and all you can do is retaliate because you don't understand some simple C++ concepts. If you don't know what RAII is, you shouldn't be coding C++ it's vitally important in writing resource and exception safe programming.

      Perhaps these links will help you:

      RAII
      SWIG
      MVC
      LOKI Library

    35. Re:Boost? Ugh by Pretor · · Score: 1

      Well I've been coding and designing systems professionally since 2000. Our systems range from time critical embedded systems with CPU resources comparable to a 16Mhz 386 to business applications using Oracle Database. The design and tools to complete each job is based on the target platform.

      And yes I would be able to create a system for your real time trading with high availability. The reason why I use my vocabulary is that it makes is possible to talk to other professionals in a concise matter. I don't need a book beside me on my desk to do my work. I do read books to improve my knowledge and performance, is that concept strange to you?

      If you didn't understand my vocabulary you should maybe open a book! Binders and adapters are a part of the standard template library. They are documented for example in the C++ Programming Language by Bjarne Stroustrup, the first edition is from 1997. I think RAII (Resource Acquisition Is Initialisation ) is pretty old but I don't know where I first read about it, every C++ book since 2000 reference it, go back to school if you don't know this. LOKI is the software library the Andrei Alexandrescu created together with his Modern C++ Design book in 2001.

      Over to patterns, sometimes they're really nice sometimes they're really, rally bad. Esp if it's used by a inexperienced designer/programmer. Anyway the observer pattern are introduced in Design Patterns by the Gamma et al, first edition is from 1995. And the MVC or actually Model View Thing is from 1979 (http://heim.ifi.uio.no/~trygver/1979/mvc-1/1979-0 5-MVC.pdf), this pattern is used in a various forms in a lot of different GUI toolkits, including MFC and GTK.

      I wouldn't consider any of these as the latest buzzwords.

    36. Re:Boost? Ugh by Anonymous Coward · · Score: 0

      >> "was and is a key goal when C++ was developed."
      > Oh really? Well thats the first time I've heard of it. Provide a link.

      http://www.research.att.com/~bs/hopl-almost-final. pdf

      especially section 2, anything on generic programming (like 7.2.1), ...

      > Well thats helpful when you're a maintenance programmer faced with 10,000 lines of code that could be
      > doing anything and you have no idea what because the guy who wrote it thought it would be cool to
      > overload every operator he could think off and to hell
      > with readability and comprehension 2 years down the line.

      we were talking about boost here, where the interfaces are reviewed to be both correct and sensible.
      your vectorAdd is a great example. The natural expression (as any mathematician will tell you) is v1 + v2.
      Yes, if you use templates and operator overloading you cannot "count cycles" any more, i.e. you have no idea if, when or how many functions are called. There might be expression templates which optimize the operation, or even offload them to the GPU.

      Of course tracing and debugging is not as easy at first, but that is mainly a matter of the experience and the approach you take. Traditional debugging by "extensive code gazing" will not work so well, but proper test cases will.

      >> "This helps to really rise the abstraction level of the language to solve problems of the problem
      >> domain, in a very efficient way."

      > Bullshit. Its no more efficient than function calling , its just a way for coders show off.

      Expression Templates are a great optimization, and operator overloading gives you a reasonable syntax
      i.e. do you really consider M = matVecMul(A, v).vecAdd(b); more readable than M = A * v + b;
      try more involved examples which include precedence, like M = A * (v1 + v2) + v3;

    37. Re:Boost? Ugh by maxwell+demon · · Score: 1

      If I saw v1 + v2, how would I know if it's adding the numerical vectors v1 and v2 or appending v2 to the end of v1 ? What if v1 and v2 are not numerical? Or do you think people should just intuitively know that for numerical vectors the + operator means element-wise addition and otherwise it means concatenation? If I saw addVector(v1, v2), how would I know it is mathematically adding the numerical vectors v1 and v2, or appending (adding) v2 to the end of v1? What if v1 and v2 are not numerical? Or do you think people should just intuitively know that for numerical vectors the addVector function means element-wise addition and otherwise it means concatenation?

      You see, the argument doesn't in any way depend on whether you write the operation as an operator or as a function. That is, it's not really an argument against operators, it's an argument for consistency in naming (operators are nothing but special names with unusual function call syntax).
      --
      The Tao of math: The numbers you can count are not the real numbers.
    38. Re:Boost? Ugh by Uzik2 · · Score: 1

      It's not THAT bad! It's only real problem is that it tries to be everything to everyone. It therefore never does a great job at anything. It's the swiss army knife of libraries. Personally I always seem to end up going for separate better optimized tools ;)

      --
      -- Programming with boost is like building a house with lego. It's a cool but I wouldn't want to live in it
    39. Re:Boost? Ugh by bzipitidoo · · Score: 2, Funny

      How about some Reverse Polish (aka postfix): v1 v2 +

      Gets rid of all those pesky parentheses, simplifies the syntax. What's not to like, unless you're a LISP fan? ;)

      For grep's sake, you could, oh, I dunno, use comments? v1 v2 +; //vectorAdd
      Or, maybe write out the function name? v1.operator+(v2);
      Possibly even specify the class name too? Not sure of the exact syntax, perhaps: Vector::v1.operator+(v2) or v1.Vector::operator+(v2). If postfix was allowed, maybe: v1 v2 Vector::operator+();

      Oh, and are you not a fan of OOP, which I thought was the whole point of C++? Otherwise shouldn't your example be v1.vectorAdd(v2) ?

      --
      Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
    40. Re:Boost? Ugh by LordKazan · · Score: 1

      Templates aren't readable?

      O'RLY?
      http://alliance.cvs.sourceforge.net/alliance/trade routes/code/core/opstack.h?revision=1.1&view=marku p
      http://alliance.cvs.sourceforge.net/alliance/trade routes/code/core/oplinkedlist.h?revision=1.1&view= markup
      http://alliance.cvs.sourceforge.net/alliance/trade routes/code/core/fe_dbl_linked_list.h?revision=1.2 &view=markup

      (before you ask: yes i have a vendetta against the STL sometimes... i like to be able to use Watch effectively for debugging and that wasn't possible w/ STL in MSVC6... in MSVC8 it's much better)

      --
      If you cannot keep politics out of your moderation remove yourself from the Mod Lottery.. NOW!
    41. Re:Boost? Ugh by Anonymous Coward · · Score: 0

      have you written a serious line of code in a professional environment in the last, decade? I don't tend to use the jargon, and i avoid anything I consider buzzwords (what they were using were NOT buzzwords) but I know I often use patterns and/or very smiliar pattersn to a lot of the ones named, and some unnamed.

      if you do serious programming in this day and age in C++, which you clearly don't since you don't know your ass from a hole in the ground when it comes to templates, then you atleast passingly know the jargon for the various programming patterns.

      Since you clearly haven't done anything serious in years SHUT THE FUCK UP and let us real programmers have a conversation your crotchety old has-never-been.

    42. Re:Boost? Ugh by statusbar · · Score: 1

      What if the types of v1 and v2 was the T in template ? Then addVector() doesn't make sense. '+' does...

      --jeffk++

      --
      ipv6 is my vpn
    43. Re:Boost? Ugh by John+Betonschaar · · Score: 1

      No , something like vectorAdd(v1,v2) would be a lot more readable and a damn site easier to grep for. Idiot.

      Calling people an idiot does not contribute to making your point. While there actually are some valid points why operator overloading is not always (maybe even most of the times) a good idea, there are also lots of cases where it *is*. You're taking your argument way out of context, which gives me the impression you're not a professional and/or experienced C++ coder (yet?). There is no silver bullet especially not in C++, seeing in how many domains it can be used. Depending on what you're writing, sometimes abstraction from the implementation and improving readability of the logic the code is implementing is much more important than improving traceability of operators etc. Imagine writing a library that has classes to represent polynomials, with methods to add, multiply, evaluate, simplify, etc. polynomials, or individual terms of them. I don't even want to know what even moderately complex code would end up like, if every operation on every different type of polynomial term has its own distinctive member function, instead of the operators also used in real mathematics. Now try asking a mathematician to debug the mathematics (ie: not the code itself) of an application you wrote using this library...

    44. Re:Boost? Ugh by paulxnuke · · Score: 1
      Boost is a very powerful solution in search of a problem. It's fun to see what the experts can do by hacking C++ "features" in unintended ways, but it's usually not something I want in our production code. I allow STL containers, but other parts of the library have to be discussed; boost is pretty much off the table, as is 99% of template metaprogramming-type stuff, particularly expression templates. For that matter, template support in VC++ is quirky enough (and changes enough between versions) that we're pretty cautious about it beyond the basics.

      If you really need GC or boost features, most functional and/or scripting languages do it far better and simpler than any bolted on kludge to C++ ever will, and are easier to learn and more fun to use. Don't try to make C++ into something it isn't, just because more and more people don't need the kind of power it offers any more, and don't want to take the time to learn it properly. Proficiency does take time, but once you know the syntax the most important skill required to use modern C++ effectively could be summed up as:

      Given the choice between 50 lines of dead simple code that anyone can understand, and 5 lines of gibberish that often takes just as long to write, can't be debugged, can't be maintained, and takes noticeably longer to compile, go with the simple solution every time (for an example, look for boost's swanky Spirit parser on USENET).


      We call it "Aim low and SHIP!" And did I mention, I use MACROS?
    45. Re:Boost? Ugh by N7DR · · Score: 2, Interesting
      I'm used to templates syntax (though I think its ugly and Stroustrup could have done a lot better)

      I was on the C++ committee at the time that templates were accepted -- my memory is that the syntax that was accepted is identical to what Bjarne originally proposed, because there were no obvious flaws in the proposal.

      It is true that if templates were being added today, I would expect the syntax to be rather different, but only because we had no idea that when we added templates we were adding a Turing-complete compile-time language. Had we known that, I am pretty sure that we would have also introduced a syntax that makes it about a million times more pleasant to actually use that feature.

    46. Re:Boost? Ugh by Viol8 · · Score: 1

      "Template metaprogramming also allows policy-based design, which essentially introduces permutations. Context vs. Context for instance. This way, you can optionally add thread safety at compile-time."

      Is there an english translation for that? And when else would you add thread safety in a compiled program , runtime?

    47. Re:Boost? Ugh by Viol8 · · Score: 1

      "Then probably we should remove the operators for built-in types as well."

      Oh hilarious , I never saw that coming!

      You're unlikely to find someone whos rewritten the functionality for adding basic types are you? So why would you ever need to look for where it occurs to debug its implementation? FFS.

    48. Re:Boost? Ugh by Viol8 · · Score: 1

      "The natural expression (as any mathematician will tell you) is v1 + v2."

      For arrays? I don't think so, anymore than it is for strings which is why other languages use "&" for string concatenation.

    49. Re:Boost? Ugh by Viol8 · · Score: 1

      "which gives me the impression you're not a professional and/or experienced C++ coder (yet?). "

      I've been doing professional coding for 14 years from everything from OS device drivers to network servers to OLTP to games mainly in C/C++ and Z80 & x86 assembler. But no , I have no experience obviously. I'm just a casual observer whose seen these flavour of the month paradigms and libraries come and go with depressing regularity with the standard issue fanboys and vested interest merchants jumping up and down about how wonderful they are. Yawn. Boost is just another that will hopefully join ACE in the Why Did They Bother? category.

    50. Re:Boost? Ugh by Viol8 · · Score: 2, Interesting

      Are you seriously using those examples as an argument FOR readability?? I hope you're just being sarcastic.

    51. Re:Boost? Ugh by swillden · · Score: 2, Informative

      It's not primarily meant for production use, rather it is a _testbed_ for future improvements to the C++ standard library. Pretty much a place where they intentionally test the bounds of the C++ language and check what kind of features would make sense in the standard.

      Huh? Where did you get that idea? The Boost libraries most definitely are intended for production use, in a wide variety of environments. From the home page:

      Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications. The Boost license encourages both commercial and non-commercial use.

      They do aim to define and refine libraries so that they may eventually be appropriate for standardization, but the *primary* purpose of the Boost libraries is to provide tools that working programmers need, to get their production work done.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    52. Re:Boost? Ugh by kazade84 · · Score: 1

      which is why other languages use "&" for string concatenation.

      Ahhh, you're a VB guy, that explains everything! :p

    53. Re:Boost? Ugh by Anonymous Coward · · Score: 0

      would be a lot more readable and a damn site easier to grep for. Idiot.

      Wow. You lost all your credibility in one line. You must be one of those old hackers with 20 years of hacking and only 10 years of experience programing. Dinosaurs that are more hacker then craftsman.

    54. Re:Boost? Ugh by KevReedUK · · Score: 1

      Sorry if this seems a bit daft, I'll admit up front that I'm comparatively new to coding, but I'm damned if I can tell just by looking at it what "dereferenePointer(p)" does...

      I assume it is the opposite of "referenePointer(p)", but WTF is referene... I've encountered many functions descriptively named after verbs describing what they do, but this is a verb I don't seem to have encountered either in code or elsewhere...

      --
      Just my $0.03 (At current exchange rates, my £0.02 is worth more than your $0.02)
    55. Re:Boost? Ugh by Anonymous Coward · · Score: 0

      Which goes a long way towards explaining why the C++ standardization process was so flawed: Adding nifty features without understanding all the ramifications. ;-)

      But, well, they made it all work, somehow. I guess we've gotta live with the standard we've got. I just wish people hadn't insisted on throwing everything and the kitchen sink in the C++ language, although I suppose that made sense back when it looked like C++ would be the only language left standing in the software industry.

    56. Re:Boost? Ugh by ardor · · Score: 1

      Read my correction above. Its Context < SingleThreaded > vs. Context < MultiThreaded > .

      The idea is to either derive from the given class (SingleThreaded or MultiThreaded), or create an instance of it in the Context class. Both classes have ScopedLock subclasses etc. but in the SingleThreaded one ScopedLock is empty. Thus the compiler optimizes it away completely, as a result you have code without synchronization stuff, which make sense when one does not use threads. In MultiThreaded, ScopeLock *does* have contents, and locks/unlocks. This way, I can change the behaviour of the class just by passing a different template argument.

      It gets even more interesting when more than one template argument is involved, for example Image . Adding support for another colorspace equals writing just another policy class (like ColorspaceLAB). I don't even have to derive it from a base class, it just has to have specific methods that get called inside of Context.

      I highly recommend that you get the book "Modern C++ Design" by Andrei Alexandrescu. It is true that there is a hype around boost, however parts of it are excellent. And for the record, I have been programming for 15 years, 68k & x86 Asm, C, C++, Java, a bit Lisp, Python, Pascal.

      --
      This sig does not contain any SCO code.
    57. Re:Boost? Ugh by IkeTo · · Score: 1

      > The effect in Java is like every pointer (or object reference or whatever you want to call
      > them) were shared_ptr (except better).

      Except that the GC implies that there is no destructors, and you never know whether finalizers are called, and if they do, when. That alone barred Java from the neat RAII technique that C++ programmers are so accustomed to.

    58. Re:Boost? Ugh by pzs · · Score: 1

      I did, because I was trying to use the Python Boost integration. It was very painful.

      You could be right that it's more powerful, but it's still annoying to need a compile tool for just *one* project that I want to use.

      Peter

    59. Re:Boost? Ugh by pzs · · Score: 2, Insightful

      Amen, brother.

      The only thing I can add to this is that an error message that only takes up 8 lines is a cissy error coming from BGL. I had errors that were multiple screenfuls. It seems somehow wrong when a tiny type error that can be fixed with maybe 3 or 4 well placed characters can be so verbose. I guess that's C++ for you.

      Peter

    60. Re:Boost? Ugh by Cyberax · · Score: 1

      Yes, it is not very easy to make Python integration work in Boost.

      But Boost developers had to settle on a particular build tool. So I guess it would not be easier for you if they used CMake or SCons :)

    61. Re:Boost? Ugh by Jeremi · · Score: 1
      You seem to like name dropping [...] Sorry , but I get tired of people of your ilk.


      If we didn't have a well-known trade vocabulary to describe the things we do, it would be very difficult to communicate effectively with other programmers. All those phrases that you are so proud of your ignorance of were invented for a reason.


      I'm not sure why you felt the need to attack the parent poster simply for describing what he likes about Boost... perhaps you were feeling insecure about your own skill set?

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    62. Re:Boost? Ugh by stonecypher · · Score: 1

      Boost strikes me as the sort of library used by people who want to show off how up to date their skills are , not people who really need to write a program to get a job done
      Then you obviously don't know much about boost. You use boost when you need smart pointers, strong portable randomness, graphing algorithms, runtime generic type behavior, CRC checks, binding behavior, type traits, prefab operators for classes, a prefab parser and/or tokeniser, finite state machines and state charting, memory pooling, portable thread wrappers, the lambda calculus, quaternions and octernions, interval mathematics, name parameterization and so on.

      If that's your idea of tools that are there to just show off, then you ain't much of a programmer, kid.

      Its bloated
      Nonsense. I'd ask you to justify that with numbers, but I'm certain you are unable.

      has a wierd syntax that differs from the C++ norm
      No it doesn't. By the way, this is the candidate library for the next version of C++, which is only around a year or two off; most compilers implement huge stretches of Boost, and in a year or two, all of them will. That supposed mystery weird syntax is about to become a permanent fundamental part of the language. Sorry, Charlie.

      and doesn't solve any problem that isn't already solved or could be done quite easily by standard C++ anyway
      Dude, this is the official library for extending the parts of C++ that aren't handled yet, and you're saying it doesn't do anything C++ can't do. Can you look at this list and say C++ already does all this with a straight face?

      What is its point except as intellectual masturbation by its authors?
      To test the future of C++ before making it permanent. This is something you'd know if you had the first clue about C++ or Boost. Unfortunately, as you've made plain to anyone reading, you don't.

      What I find hilarious is that the people you're accusing of intellectual mastErbation are the very people you're silently putting on a pedestal. You talk badly about boost in favor of what C++ can already do, but the very people who created what C++ can already do are the same people creating Boost. Hell, the library was originally created by the C++ Standards Committee Library Working Group, not that I'd expect you to know who that is.

      No this isn't a Troll
      Perhaps not intentionally.

      this is a post by someone who was forced to use Boost for a year
      And yet, you seem still to know nothing about it.
      --
      StoneCypher is Full of BS
    63. Re:Boost? Ugh by stonecypher · · Score: 1

      I used the Boost Graph Library for some research code ... Getting it to compile was a bit of a nightmare too
      Er. You do realize that the Boost Graph Library is not a compiled library, right?

      What the hell is wrong with using make like everybody else?
      Make cannot take into account compiler, platform or library differences. Boost JAM was created because the existing fix for this enormous well known problem in make, autotools/configure, is far more horrible than Make will ever be. Also, JAM is genuinely portable, whereas configure can sometimes be trusted on a different Unix than the one that created the package. There are of course documents that explain the purpose of JAM; perhaps you should read them.

      I'm sure that once you become an expert, BGL is really powerful and efficient, but I found the learning curve too steep. I just want to get in and build a working prototype quickly so I can see what I'm doing, not spend hours wading through manuals and examples to build the simplest program.
      That's a little like saying "I'm sure Oracle9i is really powerful and efficient, but I found the learning curve was too steep; I just wanted to keep a list of groceries." BGL is not a learning tool. It's a production tool. Production tools are never easy, and should never be used for experimental work.

      Boost isn't there to help you learn. It's there to help you work. If you're still learning, well, then no wonder it scares the hell out of you.
      --
      StoneCypher is Full of BS
    64. Re:Boost? Ugh by stonecypher · · Score: 2, Informative

      By definition it is both. It is important to remember that no candidate library may be admitted to C++ if it isn't production ready. The idea that Boost is not meant for production use suggests that you too might do well with a bit of catching up on the ol' intents-and-philosophies set.

      --
      StoneCypher is Full of BS
    65. Re:Boost? Ugh by stonecypher · · Score: 1

      and then using them in ways never intended that produce syntax that a plain C++ wouldn't even recognise
      Boost is the future of "plain C++" by definition. If you can't follow this code, either get better at C++ or start learning a different language, because this is where C++ is going, whether you're ready or not. The purpose of Boost is to chart and test the future of the language. If you don't like the look of the future, well, y'know how we all react to Fortran programmers...
      --
      StoneCypher is Full of BS
    66. Re:Boost? Ugh by swillden · · Score: 1

      "The natural expression (as any mathematician will tell you) is v1 + v2."

      For arrays?

      Absolutely for arrays (aka vectors). And matrices. And tensors. And dozens of other kinds of mathematical objects. Ever taken a linear algebra class? Or vector calculus? Or even an introductory physics course? If so, you've done plenty of vector addition, because mathematicians overload '+' all the time, without confusion. Take some group theory and you'll see that '+' is generally used as the group operator even though the group elements aren't necessarily even numeric in nature -- but by definition a group operator has most of the characteristics of addition, so the usage makes perfect sense.

      I don't think so, anymore than it is for strings which is why other languages use "&" for string concatenation.

      What other languages? C++, Java, C#, Eiffel, Javascript, Pascal, Ruby and Python use '+'. Perl and PHP use '.'. Smalltalk uses ','. Haskell uses '++'. Most Unix shell scripting languages do concatenation implicitly. Cecil uses '||'. So what are these languages, other than VB, that use '&'?

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    67. Re:Boost? Ugh by nuzak · · Score: 1

      > I saw v1 + v2, how would I know if it's adding the numerical vectors v1 and v2 or appending v2 to the end of v1 ?

      You know it's "vee one plus vee two". Unless you're using some insane library like Spirit, you know it's doing addition on whatever v1 and v2 are.

      Honestly, why do people constantly piss and moan that C++ isn't assembly?

      --
      Done with slashdot, done with nerds, getting a life.
    68. Re:Boost? Ugh by NoOneInParticular · · Score: 2, Insightful
      The effect in Java is like every pointer (or object reference or whatever you want to call them) were shared_ptr (except better).

      Nope. garbage collection solves one problem, memory management, but does not solve the more general issue of resource management. Incorporating a few file handles, database connections or what you have into Objects in java leads immediately to manual resource management issues. You cannot reflect a couple of resources into an object and have deterministic release behaviour unless you explicitly code for it. Shared pointers (reference counting) does cater for this, albeit at a performance cost. RAII is impossible in Java, yet commonplace in C++, with or without reference counting. They're just different, each with tradeoffs of their own, mkay?

    69. Re:Boost? Ugh by Anonymous Coward · · Score: 0

      Thank you. Prior to your post, my brain automatically transformed "referene" to "reference". Now I see that I was in error, the GP is an idiot, and you are a grammar genius. Truly, thanks.

    70. Re:Boost? Ugh by NoOneInParticular · · Score: 1
      Yes, sure. I've seen quite a few 'matrix' libraries in java, and each of them is a pain in the neck. First, so you have:

      Matrix add(Matrix arg);

      So, does this one create a new matrix, or does it modify itself and then return a reference for chaining? Well have to go to the docs. Combined with the weird aversion Java programmers have to create massive libraries of static functions (that could solve the problem)

      Then, I want to do a calculation, say, a vectorized:

      x = 1 / sqrt(2 * pi) * exp( - 0.5 * x * x )

      Note that this is a very simple calculation. The usual stuff done in this space is about 10 times larger. So, let's look at a few languages.

      C++

      x = 1 / sqrt(2*M_PI) * exp( - 0.5 * x * x );

      Matlab

      x = 1 / sqrt(2*pi) * exp( - 0.5 .* x .* x);

      Python's numarray

      x = 1 / sqrt(2*math.pi) * exp( - 0.5 * x * x);
      Fortran 90

      x = 1 / sqrt(2*math.pi) * exp( - 0.5 * x * x);

      Lisp

      (* (/ 1 (sqrt (* 2 pi)) (exp (- (* 0.5 (* x x)))))

      Java (infatuated-with-objects-version, the default):

      x = x.mult(x).mult(0.5).negate().exp().mult( 1 / sqrt(2 * Math.PI) );

      I'm sorry, java plainly sucks here, compared with practically anything. I'm sure even Perl's got better syntax. If Java programmers would finally learn that objects should simply provide the minimal number of members that would protect the data and use normal regular functions otherwise, this example could almost be safed a bit with:

      Java (Slightly saner functional version)

      x = Vector.mult(1/sqrt(2*Math.PI), Vector.mult( Vector.exp( Vector.min( Vector.mult(x,x) ))))

      Still not pretty, needlessly verbose due to the absence of namespaces (a class can do anything for anybody, right?), and more difficult to check for errors, but it's infinitely better than the previous for which you need to know the semantics of the library intimately, and should be able to read reverse polish notation. Even Lisp is clearer. Of course, due to lacking generics, you'd better generate the code for the static functions by some script, as the sheer number of overloads you need to use scalars, vectors and matrices everywhere would start killing you.

      Java has lost the numerical space due to sheer bloodymindedness w.r.t. operator overloading. Oh, and missing value types, no performant 'complex' type possible in Java.

    71. Re:Boost? Ugh by NoOneInParticular · · Score: 1

      The real fun part is where Java breaks its golden rule: strings. String: a non-primitive java object, but with an overloaded operator + that appends. Not commutative, works with every type by calling 'toString'.

    72. Re:Boost? Ugh by maxwell+demon · · Score: 1

      I hope you don't want to claim that it's considerably harder to find an implementation of operator+ than of a normally named function. Hint: The implementation always contains "operator" followed by "+".

      --
      The Tao of math: The numbers you can count are not the real numbers.
    73. Re:Boost? Ugh by brantondaveperson · · Score: 1
      shared_ptr absolutely is threadsafe. We use it in our application with over twenty threads, passing shared_ptrs around from thread to thread all the time. Provided you protect what is pointed to by the shared_ptr there are no threading issues whatsoever

      Naturally we never know with certainty on which thread a given shared_ptr will actually be destructed, but this is only a special case of the first point anyway.

    74. Re:Boost? Ugh by Rakshasa+Taisab · · Score: 1

      Are you saying it is not primarily meant as a testbed for future improvements to the C++ library? I never said it is not _intended_ for such, just about what was the primary goal of the project.

      The project was started by members of the C++ Standard Committee for this purpose.

      --
      - These characters were randomly selected.
    75. Re:Boost? Ugh by Old+Wolf · · Score: 1

      I hope you don't want to claim that it's considerably harder to find an implementation of operator+ than of a normally named function. Hint: The implementation always contains "operator" followed by "+".

      However there may or may not be whitespace between those two tokens, so a simple text-search may not be able to find it without great rigmarole (you'd have to have a search capable of finding tokens separated by any amount of whitespace, such as a regex).

      Also, it is of course harder to find calls to that operator by using a text search :)

    76. Re:Boost? Ugh by scotch · · Score: 1

      However there may or may not be whitespace between those two tokens, so a simple text-search may not be able to find it without great rigmarole (you'd have to have a search capable of finding tokens separated by any amount of whitespace, such as a regex).

      Any programmer who can't do this without thinking hard should check in his keyboard.

      --
      XML causes global warming.
    77. Re:Boost? Ugh by jhol13 · · Score: 1

      Yes, RAII is very neat, and one of the things where Java lags.

      But lets see, e.g. Wikipedia example of RAII. The file objects cannot be put into STL containers because they are not copyable. Making them copyable ... just to define how should e.g. write behave is a big task. Not worth it.

      Another example: I've got a data structure which would benefit from using shared_ptr (heavy concurrent use). Unfortunately shared_ptr is not "compatible" with normal pointer so I would have to change every user of the data structures. Hundreds of users and several thousands of code lines. Impractical.

      In e.g. Java the change would be much smaller (use ConcurrentSkipListMap instead of TreeMap), most likely doable in a week (with testing, of course).

      And this is my point. The several different ways of telling "I've got an object" is not an advantage, it is a hindrance. The different methods do have their advantages (performance/RAII/...) but in general they are just making my job harder than necessary.

      After all, the amount of file/database/... objects whose life time is within one method is several orders of magnitude rarer than memory only objects - at least for me.

    78. Re:Boost? Ugh by Anonymous Coward · · Score: 0

      Read the thread more carefully. He was complaining that '+' is used both as numerical addition and vector/string concatenation in boost.

    79. Re:Boost? Ugh by Viol8 · · Score: 1

      "The purpose of Boost is to chart and test the future of the language."

      In that case C++ is doomed to be a niche language for syntax junkies.

    80. Re:Boost? Ugh by Anonymous Coward · · Score: 0
      The idiomatic way to write the lisp expression would be

      (* (/ (sqrt (* 2 pi)))
        (exp (* -0.5 x x)))
    81. Re:Boost? Ugh by John+Betonschaar · · Score: 2, Insightful

      I was not talking about Boost, that's a completely different subject (on which I mostly disagree with you as well but lets forget about that). I've read most of your replies in this topic, and that's what I'm basing my judgement on. You cannot seriously believe that things like operator overloading, design patterns, RAII, Boost, templates and the other things you see no purpose for are all 'flavour of the month paradigms' and only useful for programmers to show off. If you do, you are not an experienced developer to me, at least not one that moved along with advancements in the field. But maybe you're just trolling by blowing your arguments completely out of proportion.

      If you really consider yourself a skilled C++ programmer you'd acknowledge that C++ provides 1001 ways to do the same thing. For some purposes using operator overloading and templates is better, for other purposes using method overloading and OO inheritance is better. Same goes for other problems C++ offers multiple solutions for. Sometimes multiple inheritance is ok, sometimes it is terrible. Heck, sometimes using 'goto' even makes sense. If you're not only consider yourself a skilled C++ programmer but also a skilled software engineer, you'd also acknowledge that code re-use and design patterns are almost always good things if applied properly, irrespective of the implementation language. If you say 'design patterns' is just new and cool terminology for clueless programmers you probably never even opened the de-facto standard work about design patterns (Gamma et. al) and browsed it a little. It's just common solutions to recurring problems, that can save you a lot of work because you don't have to re-invent them yourself. It's just design re-use on the architectural level, which is even more important than re-use on the implementation level.

      I think you should try coding up some Java, C#, D or Python some day. You'll probably be disgusted by all the 'paradigms of the month' they applied to those languages, how much re-use and design patterns are incorporated into them etc. You think it's just because the people who created the languages wanted to show off?

    82. Re:Boost? Ugh by Viol8 · · Score: 1

      "t's vitally important in writing resource and exception safe programming."

      Ah people like you crack me up. How exactly did you think programs that did that very same thing got written before someone came along and invented RAII and patterns sonny? What , you think patterns are the wheel and we all used sleds before? Jeez..

    83. Re:Boost? Ugh by dkf · · Score: 1

      Production tools are never easy
      If your production tools are never easy, you're using the wrong production tools. There is no reason why production tools should not be easy.

      Not that designing easy production tools is easy though, oh no...
      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    84. Re:Boost? Ugh by KevReedUK · · Score: 1

      No "Grammar Genius" involved... As previously stated, I'm comparatively new to coding, so couldn't be sure whether it was a mistype (I thought it could be, but you never can be 100%). Hence the question...

      For all I know, it could have been a function of some description that I have yet to encounter.

      Had I been wanting to pick holes in someone's grammar, I, as with apparently many of the posters here (yourself included???), would take advantage of the "Post Anonymously" checkbox.

      Glad to see that /. is, as ever, a truly welcoming environment to those of us seeking to learn...

      I second the sig line I have seen on a number of posts, a "-1 Sarcasmnotappreciated" mod would probably be beneficial (although possibly overused if implemented...)!

      --
      Just my $0.03 (At current exchange rates, my £0.02 is worth more than your $0.02)
    85. Re:Boost? Ugh by IkeTo · · Score: 1

      > But lets see, e.g. Wikipedia example of RAII. The file objects cannot be put into STL
      > containers because they are not copyable. Making them copyable ... just to define how
      > should e.g. write behave is a big task. Not worth it.

      Not just "not worth it", but instead "absolute nonsense". If file objects cannot be copied, it is for its good reason. If you need to put something into a container that is anything related with a file, just store a shared_ptr of it.

  12. Memory Checker by Anonymous Coward · · Score: 0
  13. 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

    1. Re:You are looking for PageHeap by WalterGR · · Score: 1

      Excellent advice. It also bears mentioning that PageHeap will work when debugging programs written in languages other than C++. From the knowledgebase article:

      Pageheap.exe is effective when used to verify any memory allocation process, including C++ style allocations new and delete, as long as the custom allocation/free functions eventually call into NT heap management interfaces (that is, RtlAllocateHeap, RtlFreeHeap).

      (Emphasis mine.) For example, here's a bug report for something written in Delphi that crashes under pageheap.

      Also, don't be tempted to use any of the following functions: IsBadWritePtr, IsBadHugeWritePtr, IsBadReadPtr, IsBadHugeReadPtr, IsBadCodePtr, IsBadStringPtr. Their use within Microsoft is deprecated as per MS's Secure Development Lifecycle. (Microsoft's resident security guru Michael Howard calls the *ReadPtr functions "CrashMyApplication" and the *WritePtr functions "CorruptMemoryAndCrashMySystem". :)

      You can read about why these functions are bad on Larry Osterman's blog, and see more deprecated functions here.

    2. Re:You are looking for PageHeap by Like2Byte · · Score: 1

      I found this interesting little blurb from the page you linked to:

      Important Pageheap.exe does not specify what the bug is, but it will crash the system when a problem is encountered.


      Ah, I can already *do* that. What about a tool that helps me *prevent* this from happening. ;)
  14. 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 Anonymous Coward · · Score: 0

      It's not accurate to say that Java/ C# are slow. If you really need to optimise, then maybe C/ C++ will do the trick. However current VM implementations are very sufficient for 90% of the application needs.

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

    3. Re:Valgrind by bms20 · · Score: 1

      Thanks for the article reference. Unfortunately, I don't buy the argument at all.

      If they re-implemented perl in java and could decisively show that "most perl benchmarks are faster in jperl than perl" then I would be interested. Until that day C/C++ will remain a faster language.

      Remember, in C++ one can always implement a custom (read dynamic) allocator, specifically for the job. Or better yet, the code paths could likely be optimized to reduce the number of calls to malloc/free, reducing the overall complexity greatly.

      -bms20

    4. Re:Valgrind by HRogge · · Score: 3, Interesting

      Another link you might like to read (just done some search on google):
      http://www.idiom.com/~zilla/Computer/javaCbenchmar k.html

      Of course you can create your own "dynamic" allocator in C++... but that doesn't make allocation/deallocation automatically faster.

      Maybe you should search for some numbers to support your argument... just by stating "I don't buy it, C++ is still faster" it doesn't become reality.

    5. Re:Valgrind by DrXym · · Score: 2, Interesting
      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

      Speed isn't everything. If your server application is network or database bound then stability and API richness is considerably more important than speed of execution. After all, does it matter that your app completes 2ms faster if it has to wait 500ms for the database to return? Or that it crashes more frequently? Or that you can't port it to new hardware because half the libs you use don't compile? Since Java offers dozens of cross-platform APIs (network communication, web services, XML parsing, crypto, database, RMI etc. ) and runs (without recompiling) on dozens of platforms AND is generally harder to bring down than C++ I would favour where speed and UI are not factors.

      Even where a UI is present, Java has it's uses. Eclipse demonstrates that Java can produce excellent cross-platform desktop applications. I think Java's weakness is definitely its UI though. While Swing is a very rich API, it's also hard to write native look and feel apps. The file picker dialog is one place where Java apps always suck. Poor look & feel is probably why Eclipse chose to use SWT instead.

      C# (.NET) obviously doesn't benefit from robust cross-platform support but it does inherit most of the same advantages of Java. It also has excellent UI support (and better layout tools) on Windows meaning that you can accomplish quite a lot in C# without dropping to C++.

    6. Re:Valgrind by bms20 · · Score: 1

      You have a good point about the supplied standard libraries.

      Much of application development comes down to choosing the correct tool for the job these days.

      I have done a hell of a lot of work in Python using Twisted these days, as it is the correct tool for the job that I am doing. C++ would have increased the amount of time required to implement the job by a large margin.

      -bms20

    7. Re:Valgrind by Idaho · · Score: 2, 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.


      It's been a few years since I last programmed in C++, but Valgrind indeed really saved the day on a regular basis. Also look into (KDE-)frontends if you think looking at text output is not very convenient. Couldn't agree more with this part, it's the best tool I've seen - and it's free software, too.

      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


      Afraid I have to disagree here though. First of all, a language is not the thing that's "slow" or "fast". It may be the case that no very efficient compilers or virtual machines exist (for a particular language). I will admit that it is hard(er) to create efficient implementations of some languages (functional languages, logic-based languages), but C# and Java are definitely not among those. Second, Java VM's used to be slow in 1997. It's 2007 now, I'd suggest you try again (and be surprised). Third, I definitely do not agree that "you're not missing out on anything special" by using C++ instead of any garbage collected language (not necessarily Java or C#). For one, you're (do I need to state the obvious here?) missing out on garbage collection! I would say garbage collection is a clear advantage in the vast majority of programming scenario's. I would even argue that it's the biggest practical advancement in programming since the introduction of the procedural paradigm - perhaps even more important than object orientation.

      Last of all, you're complaining about "language complexities" in Java/C# and (thereby) suggesting C++ is better in this regard? Hmm, I guess my sarcasm detector must be broken or something :D
      --
      Every expression is true, for a given value of 'true'
    8. Re:Valgrind by oever · · Score: 1

      I think Java's weakness is definitely its UI though.
      Which is where Jambi comes in.
      --
      DNA is the ultimate spaghetti code.
    9. Re:Valgrind by bheer · · Score: 1

      > If they re-implemented perl in java and could decisively show that "most perl benchmarks are faster in jperl than perl" then I would be interested.

      I believe they implemented Python in .NET (IronPython) and it's faster than Python for Win32 for a number of tasks. The authors do agree that there's room for lots of improvement, however. Their new v2.0 release should be interesting.

    10. Re:Valgrind by CaptnMArk · · Score: 1

      It's nice to se that they admit being slow on startup. This is important on desktop.

      (A blue-sky ideal startup time is 0.1 seconds, practically 1 second is OK, more is slow).

      Also, lazy-garbage collected programs use more memory and usually also force it in RAM (Generational collection
      helps here, at cost of using even more virtual memory).

      IMO, until garbage collector and VM are integrated in the OS kernel, memory management will suffer on desktop systems
      (aka, systems not dedicated to a single application).

    11. Re:Valgrind by LordKazan · · Score: 1

      if you don't think the java VM is slow then you aren't running many java apps. Startup time on java applets on sites i have to deal with is probably 100x greater than a C++ app doing the same function, and 20x greater than using AJAX to do the same thing.

      don't even get me started on desktop apps....

      --
      If you cannot keep politics out of your moderation remove yourself from the Mod Lottery.. NOW!
    12. Re:Valgrind by GooberToo · · Score: 1

      Speed isn't everything. If your server application is network or database bound then stability and API richness is considerably more important than speed of execution. After all, does it matter that your app completes 2ms faster if it has to wait 500ms for the database to return?

      I would like to complement your position on Java. It's rather refreshing to see someone take a realistic view of Java's strengths and weaknesses. Contrary to the usual assertion by Java zealots, Java does have weaknesses and one of its largest is its performance. Having said that, as you clearly identified, not every problem domain requires 100% of the CPU 100% of the time. As such, languages like Java, Python, Perl, and Ruby, etc. have many, many advantages other than raw performance.

      IMO, the sooner Java zealots stop saying silly things like "Java is faster than C/C++" and start preaching the real merits of Java, wider adoption will occur. Until then it simply comes across as zealotry and undeserved hero worship, and is a real turn off for the knowing masses.

    13. Re:Valgrind by GooberToo · · Score: 1

      It's been a while since I last looked at the benchmark results but I seem to recall they were only faster at some two out of twenty or so tests. In the remainder of the tests, IronPython was hidiously slow. In other words, there is still a very long road ahead for the likes of IronPython before claims of performance can be had. Then again, perhaps my comments are a release or two behind...and I'm going off memory.

    14. Re:Valgrind by bms20 · · Score: 1

      Hmm. Most of the discussions so-far in this thread have been about "langauges". Let us refine that into practices within a specific language:

      Is not a shared pointer implementation a form of garbage collection?

      What if the delete operation of a shared pointer is overridden to place that item onto a queue which is flushed when demand time is low (or memory is low)? Is this not lazy garbage collection?

      What if, instead, I placed the item onto a "recycling hash-map" - then overriding operator new, I return previously allocated instances of that item - is this not a method of implementing memory reuse, without resorting to the os to perform memory allocation.

      Sure, shared pointers get rid of memory leaks, but what about objects that consistently grow. Such programming errors are equivalent to "memory leaks" in the traditional sense, and plague applications written in Java, C#, Python, (and C++) etc....

      The bottom line here is that C++ gives you (the programmer) the flexibility to use any of the patterns found in these "advanced scripting languages". - It is just that you have to know what you are doing. -bms20

    15. 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.
    16. Re:Valgrind by Idaho · · Score: 1

      if you don't think the java VM is slow then you aren't running many java apps. Startup time on java applets on sites i have to deal with is probably 100x greater than a C++ app doing the same function, and 20x greater than using AJAX to do the same thing.


      Yes, because as we all know startup time is the only relevant performance metric, and Java is primarily used to run applets.

      OK, back to reality now? Sure, Java VM's are generally slower than compiled C++. However, my points are:
      1. Indeed. However, this has nothing to do with Java the language
      2. In most situations it doesn't matter anyway. Thanks to GC and a cleaner language design, I can develop my application in less than half the time it would cost me to do it in C++. CPU/memory is cheap compared to paying programmers, especially if your app runs only serverside.


      Btw. I am using both Eclipse and (unfortunately) Visual Studio 2005. The first is written 100% in Java, whereas I think Visual Studio is mostly written in C++. Visual Studio is definitely not much faster than Eclipse. And this isn't because it has much more functionality (because it doesn't).
      --
      Every expression is true, for a given value of 'true'
    17. Re:Valgrind by jgrahn · · Score: 1

      If they re-implemented perl in java and could decisively show that "most perl benchmarks are faster in jperl than perl" then I would be interested. Until that day C/C++ will remain a faster language.

      Doesn't it ever stick? There is no language called C/C++.

      And remember that a perl or Python interpreter is extremely and unusually painful for old malloc(). There is no good way to statically structure your allocations in a neat and efficient way. And you can't place the users hashes on the stack; everything must go on the heap. So, unless your perl interpreter does the same kind of things a JVM does, an interpreter written in one of those other languages might win.

    18. Re:Valgrind by DrXym · · Score: 2, Interesting
      I think my perspective is rounded because I'm in regular contact with C++, Java and C# every day at work. I wouldn't dream of using Java for something performance related (or I'd at least use JNI to fix the performance bottleneck) and I wouldn't dream of using it for a lightweight GUI app that I expect launch quickly.

      However I think Java is just fine in most regular roles assuming performance is no issue. I've never thought to myself that Azureus is any slower because its implemented in Java. I've even written a poker hand calculator that runs through hundreds of thousands of hands in a second. I think performance is an overrated concern for most apps.

      Even so, I still find it easier to knock together a GUI app much easier using C++ than I would in Java. Swing layout editors just stink. I don't understand what the big hangup is with Swing and visual editing since DevStudio 2005 makes it look easy with .NET 2.0.

    19. Re:Valgrind by stonecypher · · Score: 2, Informative

      Speed isn't everything. If your server application is network or database bound then stability and API richness is considerably more important than speed of execution.

      "Speed isn't everything. Why, if you start with a situation where other problems are choking you, you don't even have to think about speed!" That's called tautology.

      By the by, the programming languages you just argued for are ADA, PHP and Visual Basic.NET, whose libraries are enormous in comparison to Java or C#. Now, I do a fair amount of PHP when I'm bored, so don't get up in arms when I say this. That said, I want to point something out: there are very, very few genuinely large scale services written in PHP, C#, Java, ADA, or any of those languages.

      When it comes down to it, there are two costs: programmer time and hardware time. If you're network blocked, you buy a bigger network pipe; a dedicated box with a dedicated guaranteed ten megabit unmetered line for a year costs about a week and a half of a programmer's salary.

      But, more importantly, you never, ever, EVER get network blocked. That just doesn't happen on engineered systems. The network moves faster than any software you or anyone you know will ever write. Sure, one given pipe might fill; you just upgrade the pipe. It's relatively straightforward to find gigabit, and if you know what you're doing you can go up from there; you have almost certainly never in your life seen a system that can push a gigabit of data. Even just filling static HTTP requests at that speed can bring a heavy duty, well tuned box to its knees. I happen to be friends with a tech at one of the giant shared hosting farms; his company has over 200,000 customers, and it takes them a Quad Athlon to service the average 100 megabit pipe filled with average wordpress blogs.

      Now, I'm not saying the richness of the API doesn't matter. I'm just saying that positing a system based on filling the network is a little like designing the heater in the car in case the sun goes out. If you have enough users to fill a pipe, you can afford the next pipe up, or you need to be less retarded in setting your prices. The pipe has nothing to do with your selection of language.

      And, frankly, the idea that you have to step away from real languages to get a real API is silly. Or, haven't you ever actually looked through the standard libraries of languages like C++ and Erlang?

      After all, does it matter that your app completes 2ms faster if it has to wait 500ms for the database to return?

      If your database is taking a half second to return, you've got incredibly serious problems. And yes, in the real world, a 2ms lag matters because of the queueing problem. Have a look at one of those graphs where a modern stage server like Lightstreamer or YAWS compares itself to Apache. Apache tends to drop off logarithmically. Every time you lag 2ms, that's two more MS of customers you have to deal with during the next query.

      This is a limit flow problem, and most people get limit flow problems if you use a toilet as an analogy. Your webserver is similar to a toilet that doesn't have a stopgap. That means the bowl is always slowly filling with usage (ie, not water - say this is a train station) and you have to flush it every so often to keep things clean. The train station was well designed 50 years ago, but as population has gone up, the facilities are feeling the strain.

      Now, there's a point at which you say "does it really matter if the toilet takes three minutes to flush, if it's 20 minutes between trains?" Well, actually, yes, because that means each toilet can only service six and two thirds people per train arrival. At home-bound rush hour, you're going to get an enormous line of people outside the bathroom that keeps getting longer and longer.

      The problem with Apache is that the longer the line is, the slower the toilet flushes. See the issue now

      --
      StoneCypher is Full of BS
    20. Re:Valgrind by stonecypher · · Score: 1

      First of all, a language is not the thing that's "slow" or "fast".
      Whereas the two examples you're arguing - C# and Java - are things with which I agree on your grounds, I should point out that there are in fact such things as slow languages. Sure, the quality of the compiler or interpreter has a lot to do with it, but there are other issues too. You can't really write a fast chess AI, for example, using Erlang, because there's no way to implement in-place zobrist hashing and because the fundamental datatypes don't allow you to write the kind of code that allow fast specific hashing. Erlang's actually a very fast language in general, but that's a clean case of language design providing a clear impediment to speed.

      Other languages have similar problems. For example, pre-.NET Visual Basic had no serious support for real data structures, nor to client datastructures, meaning the programmers couldn't just implement their own (this has since changed.) Lua has no support for integer mathematics at all, something which can have an enormous impact on the speed of huge stretches of computing. Some languages fundamentally cannot be compiled at all, which does tremendous damage to their speed potential.

      Then, you could get into talking to a Fortran/Fortress or Elm/Java or Prolog/Erlang designer about the changes between the two languages whose specific purposes were to enable optimizations for speed. A lot of people who aren't comfortable with the idea of a slow language are, oddly, still comfortable with the idea of a fast language.

      In fact, one of the best examples I can give is C++: take a look into what Herb Sutter has to say about the problems caused by keyword export. He makes the surprisingly compelling case for removing the keyword based on a million different things. One of those things is the surprisingly long list of optimizations that compilers can no longer make if we just introduce that one keyword.

      That one single keyword can and does make a huge difference in the speed of output binaries in those compilers such as Comeau/EDG and ICC which both implement export and are able to turn support for it off. That's a pretty clear indemnification, in my mind, of that language design cannot impact program speed.

      Sure, maybe language design isn't the biggest issue. That doesn't mean it's a non-issue. I highly recommend you consider picking up a radical-difference language like Erlang or Mozart-OZ, and then go back to thinking about language impact on speed. The difference in approach of those two langauges to what you're probably used to is shocking, and can have tremendous impact on the fundamental design and structure of an application.

      I'm with you - you and I both disagree strongly with the viewpoint of the person to whom you're responding. However, I suggest that you're oversimplifying the situation, in the zeal to make obvious to this third party what you disagree with, and in some situations the things that I believe you're oversimplifying can become very important.
      --
      StoneCypher is Full of BS
    21. Re:Valgrind by LordKazan · · Score: 1

      every time i've used the two on the same hardware VS has been much faster (not to mention much more usable than) eclipse.

      and i hate every other MS app in existance... but they did get one right for the most part - VS

      --
      If you cannot keep politics out of your moderation remove yourself from the Mod Lottery.. NOW!
    22. Re:Valgrind by darrylo · · Score: 1

      While valgrind is very nice, IBM's (was Rational's) Purify is much better for uninitialized memory detection, if you can afford it (the Unix/linux version of purify, that is -- I don't like the windows version). The biggest issue with valgrind is that it only tells you about uninitialized variables when they are used as part of a conditional test (like an "if" or "while" statement). For example, function "A" could have an uninitialized variable that gets passed to functions "B", "C", and "D", which then store the uninitialized value like a virus into 1000 data structures. Eventually, valgrind may eventually report that an uninitialized value is being used by function "xyz". For many cases, while valgrind will detect the uninitialized value's existence, it can be very hard to divine the source. Purify, on the other hand, will tell you exactly from whence it came.

      However, purify is pretty expensive. I don't think most folks can afford it, and so valgrind is an excellent alternative.

    23. Re:Valgrind by Pseudonym · · Score: 1

      I think performance is an overrated concern for most apps.

      I disagree with that. If you're a professional, time is money, and performance always matters.

      What doesn't always matter is run-time performance. Programmer performance is often just as, or more, important. A program that takes three hours to write and ten minutes to run is inferior to one that takes an hour to write and half an hour to run, if it's only going to be run once.

      Even if it's not going to be run only once, you have to take into account the cost of deployment and maintenance (bug fixing and feature enhancement). If it takes 10 minutes to fix a bug as opposed to an hour, that's a real benefit which you can measure in dollars.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    24. Re:Valgrind by Anonymous Coward · · Score: 0

      muTorrent compared to Azureus makes Java look like a joke in terms of both CPU and memory utilization(with approximately equal functions and UI).

    25. Re:Valgrind by DrXym · · Score: 1
      What doesn't always matter is run-time performance. Programmer performance is often just as, or more, important. A program that takes three hours to write and ten minutes to run is inferior to one that takes an hour to write and half an hour to run, if it's only going to be run once.

      Well arguably Java is easier to write and maintain too as opposed to C++ so that's another legitimate reason to choose it. I find the iterative development style in most Java IDEs such as Eclipse to another reason to prefer it over C/C++ where compiling, linking and debugging gets more painful as the app grows.

    26. Re:Valgrind by Idaho · · Score: 1

      Sure, shared pointers get rid of memory leaks, but what about objects that consistently grow. Such programming errors are equivalent to "memory leaks" in the traditional sense, and plague applications written in Java, C#, Python, (and C++) etc....

      The bottom line here is that C++ gives you (the programmer) the flexibility to use any of the patterns found in these "advanced scripting languages". - It is just that you have to know what you are doing. -bms20


      You can avoid those memory leaks in Java just as well though. However, you don't have to bother in the (majority of) cases where the GC works just fine already. Whereas C++ certainly gives more flexibility, it also *forces* you to actually use that flexibility all the time (at least where GC is concerned). I mean, you could argue the same way that programming in assembly language is even more flexible...(even less restrictions). Which it is, of course, but sometimes, you do *not* want some things to be flexible, you just want to have sensible defaults and perhaps the ability to override them when necessary. I'll admit that Java sometimes fails to provide the latter.

      However, to address the example you mention, you can set no-longer-used fields that refer to large substructures (e.g. a parsed XML document) of long-lived objects (e.g. the main application object) to 'null' explicitly to make sure they will be garbage collected. This is still a *long* way from having to (explicitly) free *every* object in your entire application.
      --
      Every expression is true, for a given value of 'true'
    27. Re:Valgrind by GooberToo · · Score: 1

      What doesn't always matter is run-time performance. Programmer performance is often just as, or more, important. A program that takes three hours to write and ten minutes to run is inferior to one that takes an hour to write and half an hour to run, if it's only going to be run once.

      You're pretty much alone in your analysis. To boot, you stacked the deck by creating a performance critical requirement. Most studies confirm that, given your example, what would take three hours to write in Java will take six to eight in C/C++. And sense no one sane will be using Java for performance critical code, your runtime comparisons can be ignored. After all, no one cares if it takes your Java app 10ms to process a transaction verses 1ms. If they did, they wouldn't (shouldn't) be using Java.

      At the end of the day, Java, Python, Ruby, Perl, all have their place. Stacking the deck to ultimately waste development time is silly.

    28. Re:Valgrind by Pseudonym · · Score: 1

      You're pretty much alone in your analysis.

      Read back over what I wrote. What I said was pretty much a tautology: If time is money, then spend your time wisely.

      And for the record, I said what I said to agree with your main point! For many kinds of application, Java/Python/Ruby/Perl/etc are closer to optimal for programmer performance, so can often win in a cost/benefit analysis.

      Incidentally, P.J. Plauger pointed out that hard real-time performance is also always important. If your monthly payroll processing program takes more than a month to run, it's useless. And if a program takes more than about two years to run on today's hardware, it's going to complete sooner if you wait six months and buy a faster computer.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    29. Re:Valgrind by GooberToo · · Score: 1

      Then I misunderstood.

      As for the rest, we've read that but for the most part, it's just silly. Issues with timeframes like that are simply not issues for the bulk of the computing world. They were when 486s were king but these days, the gap (what desktop computes can do versus can't in a reasonable window) is so large, it's just not a concern with discusion unless you have legitimate reason to raise it.

      Of course, that does not mean performance is altogether ignored its just that performance these days isn't normally "can we or can't we", rather, it's are we willing to suffer a 20% hit? And when it does matter, languages like C/C++ are normally picked. These days, the problem domains where language choice is critical (hard real time, FPS game, simulation, etc) is pretty well known up front by experienced coders; and driven by a performance requirement. Performance requirements are a requirement or they are not. Just because a performance requirement is not given doesn't mean common sense goes out the window; thusly, the silliness of the often preached comments.

    30. Re:Valgrind by GreatBunzinni · · Score: 1

      Maybe you should search for some numbers to support your argument... just by stating "I don't buy it, C++ is still faster" it doesn't become reality.

      Indeed. Thankfully, there is quite a lot of information about the lagging performance of Java compared to other languages, including C++. Care for some benchmarks? Then check this one out: g++ C++ Vs Java JDK client benchmarks.

      You see, just by stating "Java is as fast if not faster than C++" it doesn't become reality.

      --
      Slashdot, fix your code or at least hire someone who is competent at it to do it for you.
  15. Windows Resource Kit by Anonymous Coward · · Score: 0

    I am not sure about its availability for Windows XP, but I have used the Windows Server 2003 Resource Kit tools to successfully locate memory leaks in Windows dlls. First, you have to link with /DEBUG to get any meaningful results. Then run memtriage on the pid to get the heap address range and size allocation of all dlls attached to the given process, then use dh (dump heap) to determine which of the address ranges is for your resource.

    If you see growth in successive executions of memtriage (which can be set to sample the heap over any defined time interval and for any number of iterations and all heap data is written to a log file) then analysis of corresponding executions of dh will tell you where memory is being allocated and not being freed.

  16. eFence by cannonfodda · · Score: 4, Interesting

    I haven't used it for a while, but I used to use Bruce Peren's efence for bits of malloc debugging, it hasn't been actively developed for ages but it's pretty light weight if that's what you need. There appears to be an up to date branch DUMA which I haven't tried. As far as I remember you can use efence under WIN and DUMA claims to work......

    Unfortunately, what you prolly want is valgrind or purify.

    --
    Hmmmmmm
    1. Re:eFence by jcupitt65 · · Score: 1

      Programs run quickly under efence, but sadly memory use will balloon. It (I hope I have this right) puts each malloc into a separate page with guards either end. So every tiny strdup() will use some huge amount of your address space. It's not practical for anything bigger than rather small.

      valgrind takes the opposite approach: it does all the checking in software, so it runs slowly (about 1/20th of real speed, the last time I measured it), but is much more modest in the amount of RAM it needs (though it still needs a lot).

      This is one area where every developer really needs 64-bit processor. I have 8GB in my desktop machine now and I can run even the largest project I work on with full memory checks. It's wonderful.

  17. Re:Duh! by WrongSizeGlass · · Score: 4, Funny

    Replace new/delete, malloc/free, whatever/whichever, with your own tracking version. In the end you may come out with an even better idea of memory handling for whatever you are working on at the time. God-awful simple you idiot !! You disgust me that you are so stupid !! Just replace that post with your own comment system, such as replacing God-awful with I'm, idiot with smart, disgust with inspire and stupid with curious.
  18. Purify is what you need by Anonymous Coward · · Score: 1, Insightful

    Purify has been considered the best solution for this problem for many years. (How many readers have their 'Purify Mug'?)

    Linux developers can use Valgrind, which is also very good and is free. But it won't run on your platform.

    Then there are the static checking tools like Coverity. I believe that they do great things, though I have never used them. If you are a big company I think it would be well worth getting them to talk to you; you would probably find it intellectually interesting, if nothing else. There are other tools in the same field; Wikipedia has a list.

    You may find that Purify is too slow. It has various options that you can tweak. It also benefits from having loads of RAM (steal it from your colleagues while they have lunch). But basically you need to live with the speed and either be patient or hack your application to go straight to the problematic bit.

    In my experience this sort of debugging is always painful, and the lesson it teaches us is to *not put the f***ing bugs in the code in the first place!* By that I mean:

    - Avoid dynamic memory allocation when possible (i.e. use std containers instead).
    - Every time you type 'new' or 'malloc', think to yourself "where does this get deleted/freed?"; ideally the call to delete or free should be a few lines away from the call to new or malloc and it should be blindingly obvious that they occur in pairs.
    - Be really clear about ownership of pointers.
    - Use smart pointers (like the Boost scoped_ptr and shared_ptr) when appropriate.
    - Avoid pointer arithmetic.
    - Don't use a NULL sentinel value.

    Every time you find yourself doing one of these "bad" things, try to remember your last epic all-night debug session with Purify and fix it....

    By following these sorts of practices, I have managed to avoid any nasty memory-allocated related bugs for a few years. But of course it doesn't help with your legacy codebase.

    1. Re:Purify is what you need by ardor · · Score: 1

      You forgot one important thing: RAII.

      Stuff the mem allocation in the constructor, or at least set the pointer to zero there. Call delete in the destructor. This avoids memleaks and is exception-safe.

      --
      This sig does not contain any SCO code.
    2. Re:Purify is what you need by HRogge · · Score: 1

      You will just get a "chicken-egg" problem with this argument, because it transform the problem "who deallocate my resource" to "who deallocate my class".

      RAII helps to reduce the complexity of resource allocation because you can group them, but it doesn't solve the basic problem.

    3. Re:Purify is what you need by ardor · · Score: 1

      Ideally, dynamic allocation should be encapsulated in classes which are guaranteed to be deallocated, either by simply being stack objects, or by a delete call that always - really always gets called.

      Then, RAII does work.

      --
      This sig does not contain any SCO code.
    4. Re:Purify is what you need by Craig+Ringer · · Score: 1

      Some more points:

      • Don't forget std::auto_ptr<>. It's a great and exception safe way to limit the lifetime of anything allocated using the non-array form of operator new
      • Whenever you see operator new or malloc() think "is there any chance any exception could be thrown between here and the call to operator delete or free()?" . If the answer is "yes", or you're feeling sensibly paranoid, wrap the allocated object up in a stack-based container (think std::auto_ptr and ilk) that'll deallocate it when it goes out of scope.
      • Consider transferring ownership of objects using std::auto_ptr so that you know that in your code, a "bare" ptr does not ever constitute ownership. This isn't viable if you hand memory to/from external libraries a lot, or use malloc() & free().
    5. Re:Purify is what you need by Craig+Ringer · · Score: 1

      Not really - you can rely on the standard & guaranteed rules about the behaviour of stack objects.

      You know that if you have:

      {
      auto_ptr<A> a(new A());
      auto_ptr<B> b(new B());
      // blah blah
      }

      then b's object will be destroyed when it exits scope (due to an explicit or implicit return or an exception - not a long jump, but if you're using explicit long jumps you should be worrying about lots more than this). You also know that b will be destroyed before a. The semantics of copying `a' or `b' are well defined and transfer ownership, so you can return `a' and know you're transferring ownership.

      If someone changes the above to:

      {
      auto_ptr<A> a(new A());
      auto_ptr<B> b(new B());
      // blah blah
      if (!fred)
      throw std::logic_error("oops!");
      const Fred::const_iterator itEnd = fred->end();
      for (Fred::const iterator it = fred->begin(); it != itEnd; ++it)
      if (*it) return *it;
      return 0xDEADBEEF;
      }

      then you can feel safe in the knowledge that they haven't introduced a leak of `a' or `b' without a genuine effort of stupidity.

      More complex RAII mechanisms exist, but they all rely on the same core concepts of using the inherent lifetime of simpler objects to manage heap-allocated objects in safe and well defined ways.

      (PS: Posting code combined with text with civilized formatting and line wrapping on ./ SUCKS.)

    6. Re:Purify is what you need by jonwil · · Score: 1

      If you are looking for a static analysis tool, check out PREFast. If your code is able to be compiled with Visual C++ 2005, PREFast can analyze it and find potential issues in your code. Plus, its 100% free (if you download the latest platform SDK and use the compiler that is included with that SDK)

  19. Visual Leak Detector by Tucano · · Score: 3, Interesting

    I have tried mainly Boundschecker and Purify, and they were usually quite slow and difficult to set up and produced lots of spurious results. Also, quite often they simply didn't work at all and refused to run certain programs. A few years ago I reduced the problem to a 10 line C++ program that would crash Boundschecker or Purify, can't remember anymore which one it was.

    In any case, Visual Leak Detector is a free memory checking tool. It's only for Windows / Visual Studio, but if you are using that, VLD is awesome: http://www.codeproject.com/tools/visualleakdetecto r.asp

    It's super easy to set up, just #include "vld.h" somewhere in your program, and then run the debug mode. No need to rebuild everything in instrumented mode, and no false results (at least I haven't got any). Real memory leaks will be reported in the output window of the IDE.

    1. Re:Visual Leak Detector by BillGatesLoveChild · · Score: 1

      mod parent useful. Thanks for the link.

      The Visual Studio built-in memory tracing tools are out of the stone age. Why should every programmer on Earth have to write their own memory traces? Surely someone at Microsoft can do it "properly"?

    2. Re:Visual Leak Detector by LizardKing · · Score: 1

      I have tried mainly Boundschecker and Purify, and they were usually quite slow and difficult to set up and produced lots of spurious results.

      I found structure your code with Purify in mind, then you an avoid the spurious warnings and errors. This wasn't a bad things as it discourages use of globally declared pointers, often leading to more modular code. The only spurious warning that I'm usually left with is to do with leaks when adding environment variables, as this memory becomes "owned" by the environment array and is implicitly freed up when exiting.

    3. Re:Visual Leak Detector by 280Z28 · · Score: 1

      VLD is highly underrated. It's so easy to use, some of my students were using it without help in a first semester programming class. http://dmoulding.googlepages.com/vld

      --
      Turning coffee into code.
  20. valgrind by sashang · · Score: 1

    valgrind...oh but you're using windows.

  21. Roll Your Own by bsmoor01 · · Score: 1

    I write C++ for embedded systems, and I needed a decent heap checker, so I rolled my own. It only took a few hours to write.

    Of course, I basically copied the mechanism of tools like efence or DUMA, but I was able to tweak the tool to do exactly what I needed it to do. You may want to try the same approach.

    -Seth

    1. Re:Roll Your Own by Doctor+Memory · · Score: 2, Interesting

      Exactly my experience. I didn't know Electric Fence existed (and it may not have, this was back in '92-'93), so I wrote my own malloc replacement with bounds checking. It didn't eat up much more memory (I think around 64 bytes/allocation) or use a whole lot of CPU (basically, it walked the heap checking for corruption every N allocations, and N was configurable down to 1).

      I still remember the first time I tested it; I allocated some memory, then dumped the heap. I saw the block I had allocated, but there was another 2K block allocated that I hadn't! Fortunately I was dumping the contents along with the size, and I quickly figured out that printf() was calling my allocator too! (I had written replacements for [mc]alloc() and free(), and used the same names so I could instrument existing code w/o having to rewrite it.)

      --
      Just junk food for thought...
  22. 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.

    1. Re:I must agree - Purify is it. by CodeArtisan · · Score: 1

      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%. I have had my team use Purify too, with great success. A few years ago I also tried out Insure++ from Parasoft, which seemed to be of similar, if not slightly better, quality.
    2. Re:I must agree - Purify is it. by John+Betonschaar · · Score: 2, Informative

      [i]A few years ago I also tried out Insure++ from Parasoft, which seemed to be of similar, if not slightly better, quality.[/i]

      We 'use' Insure++ as well, but unfortunately 'using it' is limited to tracking down arcane, semi-valid C++ constructs in our code that Insure++ b0rks on. Insure++ supposed to be a pretty advanced tool, but it is not actively maintained anymore and it's full of limitations that make it almost unusable for existing codebases. Especially stuff with templates, stuff using classes from external namespaces and dodgy C++ constructs that compile without warnings on every compiler I know will make Insure++ instrumentation fail. Also, linking the instrumented source files together fails on 1 out of every 10 object files, especially if they also link against third-party static libs (.a on linux). Sometimes you can fix this, but most of the time it is completely unclear why the thing fails. This effectively rendere the whole tool useless as you cannot be sure there will be no problems left in the non-instrumented parts of your codebase. And in those cases instrumentation *does* work, the output you'll get when running the instrumented binaries is sometimes really unclear, confusing or downright nonsense.

      Last but not least, Parasoft support is awful. We've been told some of our linkage problems, for which we filed bug reports, would be fixed in a later release. No new version was released for 1.5 years, and on multiple inquiries about this we did not even get a reply. Then, all of a sudden Parasoft released a new version a while ago, which we found out about 4 months later as they did not bother to notify us about it...

  23. Netcraft confirms: Java is slow by zBoD · · Score: 0

    ... not

    --
    BoD
  24. Python memory checker? by Anonymous Coward · · Score: 0

    Does anyone know of any good memory checkers that can understand python's weird ass memory manager from back in '92.

  25. Glowcode! by Soulshift · · Score: 1

    Glowcode is a memory allocation watchdog and code profiler rolled into one. IMO, it has the best implemented features of its class, and is speedy and lightweight to boot. On top of that, it's useful for checking run-time memory leakage that may be masked by the deallocations that happen at the end of your program. I use it to find those odd leaks that only happen when you do a specific action, for example. A very useful tool.

    --
    node-def: a tactical hacking sim. Now in open beta.
  26. A second vote for Valgrind by RatCommander · · Score: 3, Insightful

    Valgrind's default memcheck tool is an excellent way of finding memory errors - ranging from extremely subtle to obvious. In addition, Valgrind can be used as a code profiler, cache simulator and many other things. It really is an excellent tool - I recommend it to anybody writing C++.

    --
    "It is better to die for an idea that will live than to live for an idea that will die" - Steve Biko
    1. Re:A second vote for Valgrind by HungWeiLo · · Score: 1

      Valgrind is nice - I'd like to use it but I couldn't find support for the arm platform.

      I ended up using ccmalloc. It even claims to do multi-threaded apps too, although we found a bug in that portion of it but it was no biggie since we had the source.

      --
      There are a huge number of yeast infections in this county. Probably because we're downriver from the bread factory.
  27. All the world is not a PC by tepples · · Score: 1

    How fast does Java run on a handheld device with a 67 MHz CPU and 4 MB of RAM? Over forty million of these devices have already been deployed.

    1. Re:All the world is not a PC by HRogge · · Score: 1

      1.) cpu speed is a red red herring. Of course both C++ and java will be x times faster/slower on a machine with an x times faster/slower processor (if anything else stays the same).

      2.) just look up the phrase "j2me" for java runtimes designed for embedded devices.

    2. Re:All the world is not a PC by FJGreer · · Score: 1

      my moto razr runs java well enough, and I do write code for it

      --
      Behold! Uh, what was I going to say?
  28. And a third one by Lisandro · · Score: 1

    Valgrind is, by far, one of the most useful tools i've ever came across for C/C++ developing. It's a shame it runs only on Linux - i bet a lot of Windows software would be much less leak-proof if such an excellent (and free) tool were available for them.

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

  30. Purify by supersnail · · Score: 1

    Expensive little toy from Rational.

    It profiles memory allocation on existing executables.

    Produces thousands of lines of output, most of which you can ignore after revewing the code, but it does catch almost everything.

    --
    Old COBOL programmers never die. They just code in C.
  31. Memory Validator by PipingSnail · · Score: 1
    You could try Memory Validator from Software Verification. http://www.softwareverify.com/cpp/memory/index.htm l

    Provides a lot more statistics than Purify or BoundsChecker.
    Works with Visual Studio (C++ and VB), Metrowerks, Delphi, Fortran and third party allocators such as CherryStone (or even an allocator you wrote yourself).
    Very customizable.

    Some people run sessions with billions of allocations tracked by Memory Validator
    http://www.softwareverify.com/testimonials.html

    Stephen
    (Disclaimer: I work for SVL)

  32. Give Gimpel's PC Lint a try by mike_diack · · Score: 1

    Disclaimer - I have no connection with Gimpel (http://www.gimpel.com), but their tool PC-Lint is very good and quite cheap. I swear by it (not at it!). It's the best development tool I've bought, IMHO. The people at the forum are generally very handy. In case you're not aware it's a very powerful static analyser.

    It can find a significant number of memory "abuses" in version 8 - if you get access to it/buy a copy, ensure you switch on at least the following warnings in your lint options file:

    415
    416
    419
    420
    421
    423
    429
    433
    661
    662
    669
    670
    672
    796
    797
    803
    804
    449

    Also if you have the high end version of Visual Studio 2005 (Team Edition For Software Developers is the only one that has it), have a look at its /analyze command line option (aka PreFast). This provides vaguely lint like static analysis and might be of some help - although I've found it to be pretty poor compared to PC Lint.

    Mike

    --
    Linux fan and Win32 developer
  33. Roll your own! by Nursie · · Score: 1

    I've done it in C before. Helps if you have already redefined malloc/calloc/realloc/free, if not then replace all calls to these (and new, delete etc) with calls to your versions. Make the code call macros which record the line and file number. IE -

    void* my_malloc(size, linenum, filename);

    #define my_malloc_macro(size) my_malloc(size, __LINE__, __FILE__)

    my_malloc_macro is what code calls when it wants a chunk of heap.

    When new memory is allocated my_malloc (or whatever) adds a copy of the calling line and file name to a list or hash table along with the pointer value and the size.
    Then free searches the list of allocated memory for the relevant pointer value and removes it.

    Then simply add another function to display the memory usage. You can see what's in place at any one time or (what I found useful) get it to dump out everything still allocated just before the program ends. Assuming you have a clean shutdown process.

    Of course you get into problems with threads, I was lucky enough to be using a set of runtime libraries that provided a "Stop all other threads" and a "restart all other threads" call. It slows your program down significantly, but it still works well.

    1. Re:Roll your own! by ThirdPrize · · Score: 0

      The problem is that you have to do this.

      --
      I have excellent Karma and I am not afraid to Troll it.
    2. Re:Roll your own! by Anonymous Coward · · Score: 0

      What happens when __LINE__ and __FILE__ are precompiled first and then the define? :)
      I mention this because I code on alot of different OS and that define trick will not work on all systems.

    3. Re:Roll your own! by Anonymous Coward · · Score: 0

      Then your compiler is not standards complaint. Get a better one.

    4. Re:Roll your own! by Anonymous Coward · · Score: 1, Interesting

      Yes,

      Rolling your own is much easier than it sounds. Reference counting can be done by mere mortals.

      I would say that using a self-programmed memory checker to keep track of memory leaks and then fix them in your code is better than just tossing the mis-allocated memory manually. This way the memory checker can be tossed in the release version, leaving lean and mean c++ code - which is why you code in c++ anyway.

      Also, most serious memory leaks are the result of conceptual confusion within code and not a simply a matter of failing to write a delete for each new. In a garbage collected language, the same confusion leads to memory hogging, stuck-loops and data-corruption. Thus c++'s lack of automatic memory management mean may seem like a terrible problem but isn't that much worse than other languages because no language can save you from your own stupidity.

      Ta...

    5. Re:Roll your own! by Nursie · · Score: 1

      I respectfully disagree.

      Keeping track of what you have in memory is a great way to find out what you're using and when, and find ways of controlling it.

      And it's dead simple, plus you don't then need the GC or reference counter at runtime, you #define it out for production builds.

  34. Most people can't understand Purify's output by Anonymous Coward · · Score: 5, Insightful
    Most people can't understand Purify's output, and I've actually ran across coders who actually believe their code can't be as bad a Purify says it is.

    For example, this code has serious issues:

    extern string method_that_returns_string_object();
    char *ptr;
          .
          .
          .
    ptr = method_that_returns_string_object();
          .
          . . That actually will compile, and seem to "work". But it's horribly wrong, and Purify will find the problems.

    And FWIW, I've used Purify on massive apps, and found huge problems that the developers didn't even know were there. On one project, they couldn't explain why their "perfect" app kept crashing, either. Worse for them, I had been hired as a consultant to fix their problems that they couldn't seem believe existed (HINT: your boss hired someone from the outside...), and after watching the team flail and spend literally almost a man-year trying to find one memory bug, I finally had enough of "advice giving" being ignored and got on their system, linked their app under Purify, ran it, and found the bug - a double delete of an object from two different threads. It all took me about fifteen minutes. I did that in front of their management. I made my point.

    Purify (and like tools) are a great help. Not using them is like trying to build a house without power tools. Yeah, it can be done. But what would you think if hired a builder to make your house and his team showed up carrying hand saws? Oh, and you are paying that team to hand-saw all the lumber...

    What would you think of that builder?

    Yet, when a developer asks for tools like Purify, management often balks. Because 1) they're shortsighted, and 2) developers don't know how to use such tools.

    Like I said - what would you think of a construction company where the workers don't know how to use modern power tools to help their productivity?

    Well, you just put yourself in that category.

    Yes, Purify is somewhat slower than running without Purify. But it's a lot faster than most other full-memory checking methods. If you're worried about speed, link against the Win32 debug libraries - they'll at least show problems with double free() calls, access of free()'d and deleted objects, etc. And without too much performance problems.
    1. Re:Most people can't understand Purify's output by Anonymous Coward · · Score: 0

      For example, this code has serious issues:

      extern string method_that_returns_string_object(); char *ptr; ptr = method_that_returns_string_object(); That actually will compile, and seem to "work". But it's horribly wrong, and Purify will find the problems. Really? When I do that I get:

      stringtest.cpp:8: error: cannot convert 'std::string' to 'char*' in assignment What retarded compiler is it that fails to find this error?
    2. Re:Most people can't understand Purify's output by stonecypher · · Score: 1

      On one project, [...] I had been hired as a consultant to fix their problems [...] and after watching the team [... ] spend literally almost a man-year [...] I finally [...] found the bug. It all took me about fifteen minutes. [... ] I made my point.
      You've actually made several points here. I wonder if you realize how it looks for you to brag about taking almost a year to do a 15 minute job that other engineers needed your help with and were stuck on, when apparently that was the entire reason you were hired in the first place.

      This sort of wasting time to try to make other people look bad is specifically why I refuse to hire outside consultants. Pitting one's own workers against one another leads to the most ridiculous, counterproductive and starkly sanctimonious destructive "I'm better than you" driven nonsense...
      --
      StoneCypher is Full of BS
    3. Re:Most people can't understand Purify's output by demi · · Score: 1

      But what would you think if hired a builder to make your house and his team showed up carrying hand saws? Oh, and you are paying that team to hand-saw all the lumber...

      What would you think of that builder?

      I would think to myself: "Wow, that's like the construction equivalent of using C++."

      --
      demi
    4. Re:Most people can't understand Purify's output by apankrat · · Score: 1

      > That actually will compile

      Actually it won't. There is no char * casting operator in std::string.

      --
      3.243F6A8885A308D313
    5. Re:Most people can't understand Purify's output by Anonymous Coward · · Score: 0

      You'd rather just let your guys suck and stumble along with the blind leading the blind?

  35. Do it yourself by Skizmo · · Score: 0

    Why not write memleak free software ?? .. ojeah .. overloading the new and delete so you can track your own stuff isn't that hard.

    1. Re:Do it yourself by maxwell+demon · · Score: 1

      Why not write memleak free software ??

      Because the software has already been written? From the summary: "It's a legacy app"
      --
      The Tao of math: The numbers you can count are not the real numbers.
  36. Port? by Craig+Ringer · · Score: 1

    If your app is already reasonably portable, consider porting to Linux solely to use Valgrind. It's that good. Otherwise, have you looked at Rational's Purify? I haven't used it myself but hear it has some pluses and minuses as compared to Valgrind, but is worth a look.

    I develop cross platform applications, and I find valgrind incredibly helpful, especially when integrated into my unit tests and combined with a suppressions file that hides any false positives from platform libraries etc.

    As for shared_ptr, please DO NOT think of shared_ptr as a complete memory management and leak protection solution. Smart pointers in general and shared_ptr in particular are NOT a magic band aid. Slapping shared_ptr use into a design won't necessarily fix your lifetime & memory management issues, it's quite likely to just hide them and introduce new and fun bugs where object 1 *thought* it was manipulating object 2's fred, but it was actually manipulating an obsolete and unreferenced copy of object 2's fred. And so on. Ownership and lifetime still need careful thought, and it can be better to use good old auto_ptr<>, direct membership, etc rather than shared_ptr in many situations. Also remember that the use of dtors that affect anything outside the object its self is likely to lead directly to foaming insanity when combined with shared_ptr use.

    Get your ownership and lifetime issues thought out well, and *then* think about introducing a shared ownership model if the situation warrants. Don't just slap shared_ptr<foo> in everywhere you use foo* and expect magic.

  37. Don't allocate or free = no leaks = need no tools by seniorcoder · · Score: 5, Insightful

    We are running many high speed financial message processing applications. A crash for any reason (including a leak) would be very costly for us.

    We pre-allocate pools of objects at startup and then re-use them. No other memory is allocated or freed while the process is running. Our pools of reusable objects are monitored very carefully as an object that isn't release back to its pool when the job is done is akin to a memory leak. Use of sentries to automatically release objects back to the pools when they fall out of scope is mandatory.

    So my answer is to the problem is:
    1. Use sentries (or some other mechanism) to guarantee memory is released.
    2. Don't allocate except at startup.
    3. No need for elaborate tools due to the above.

    I'm sure that not all applications data usage would fit into this model, but it is surprising how many can.

    We have seen some leaks in our applications. These were tracked down to STL internally leaking. They weren't generally very large and therefore we continue to live with them.

    On the subject of garbage collectors, some of our colleagues use Java and .NET. Both sets of colleagues have had major performance problems caused directly by the garbage collectors kicking in and consuming vast CPU power while they did their thing. The result was a failure to process messages in a timely manner in our high speed environment. The solution in both languages was to use pools of reusable objects and never cause their reference counts to drop to 0. Thus they implemented the very same mechanism that we use in C++ and avoided the garbage collectors.

    So don't think that a garbage collector is the solution. Perhaps in less demanding applications it is a potential answer.

    Lastly, I strongly dislike anything from Rational. I find them overpriced unreliable bloatware (YMMV). Purify used to be good some time ago, but those days are long gone.

    I echo what others have said above. You are a developer. You know your requirements. Build a simple tool to monitor and check your usage. For us it was managed pools of re-usable objects.

  38. Those "skilled coders" must not code much by Anonymous Coward · · Score: 0

    If you write a lot of code, you WILL make mistakes like memory leaks. A lot of them. If you don't think so, you're living in fantasy land and you're nowhere near as good a coder as you think you are.

    I'd say that one of the very first steps in making yourself into truly a good coder is realizing that you WILL make LOTS of mistakes. Which is why every truly good coder I've ever met has absolutely no qualms about letting anyone else see their code - good coders want more eyes to look for the mistakes they know they made.

    Of course, when you termed them "skilled coders", you didn't characterize the level of skill. "Poorly skilled" is still a subset of "skilled"...

    1. Re:Those "skilled coders" must not code much by etresoft · · Score: 1

      Coward, I agree with most of that. Memory leaks, however, are an avoidable problem. As others have already stated, you don't have to use new/delete and pass pointers and ownership unless you don't know any better.

    2. Re:Those "skilled coders" must not code much by ShakaUVM · · Score: 2, Insightful

      >>If you write a lot of code, you WILL make mistakes like memory leaks. A lot of them. If you don't think so, you're living in
      >>fantasy land and you're nowhere near as good a coder as you think you are.

      Pfft.

      Actually, good coding habits will indeed work.

      We were three people coding a 100,000 line program, 0 memory leaks. C.

  39. And a Fourth - Valgrind is amazing by thaig · · Score: 1

    Can't find the best place to shout this loud enough "Valgrind is AMAZING!" :-)

    It really is awesome. I used it on my library of portable data structures (C++ XML parser, compression and encryption stuff). I tested on Linux and still got the benefit on Symbian and Win Mobile when I recompiled it for those platforms.

    I had a test suite that exercised a fair it of the library and ran the tests on Linux under Valgrind. The test suite would often run perfectly but Valgrind would spot memory handling errors that didn't have any consequences in that particular test but would have in other circumstances.

    You don't have to compile special support for it into your programs. It produces some useful output even for non-debug versions of your code.

    What Valgrind does is take you 50% of the way towards the convenience of a garbage collected language. You spend a lot less time farting around with minor details but still more than if you were using a GC langage. Valgrind generously rewards people who write representative test code.

    --
    This is all just my personal opinion.
    1. Re:And a Fourth - Valgrind is amazing by mr_stinky_britches · · Score: 1

      And a fifth - in C and C++ I have used valgrind for memory leak checking and in my experience valgrind has worked WONDERFULLY to make sure that what you intended to happen is actually happening, (rather than a leak).

      It is too bad there is not a website (at least not that I am aware of) which is dedicated to finding and spreading the word about essential tools like valgrind. If any of you know about this kind of a resource I would be grateful if you let me know.

      Thanks.

      MrStinkyBritches

      --
      Censorship is obscene. Patriotism is bigotry. Faith is a vice. Slashdot 2.0 sucks.
    2. Re:And a Fourth - Valgrind is amazing by happyfrogcow · · Score: 1

      I also agree. I used Valgrind back about a year ago or so. It totally rocked. I mostly used it as a profiler, but it also happened to tell me where the leaks where.

      Valgrind, FTW!

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

  41. CPPCLI? by DSmith1974 · · Score: 1

    Seeing as your targeting Windows, why not use C++/CLI and get the very same memory management as C# ?

    --
    It is not immoral to create the human species - with or without ceremony, Samuel Clemens.
    1. Re:CPPCLI? by Yuioup · · Score: 1

      That's what I was wondering about. I believe it's called "Managed C++"

      Y

    2. Re:CPPCLI? by DSmith1974 · · Score: 1

      It was originally called 'Managed Extensions for C++' or just 'MC++' for short back with VS2002.NET and it was ugly. Because the language was still ANSI Standard C++ compiler specific keywords had to start with a double under-score making its readability close to zero. With VS2005 MS have created a new language C++/CLI which has been accepted as a new standard by ECMA - 'Standard ECMA-372' - http://www.ecma-international.org/publications/sta ndards/Ecma-372.htm Thanks to the new keywords the flow of the language is much more natural and C++ is now considered a first-class .NET language - the only in fact, that lets you mix and match managed and unmanaged code - so you don't have to throw away all of your MFC and ATL libraries, and can extend existing frameworks with managed controls. It's also much closer to the CLI than any other language so you can perform tweaks that no other language can do. If we'd had this back in the days of .NET v1 I doubt whether C# would've taken off much more than VB.NET - now everyone's a C# programmer and a good C++ programmer is even harder to find than they used to be. In short, C# is the new VB - programming for the masses. For server based, semi real-time/distributed systems work the good news is that C++/CLI has caught up (and overtaken) the rest of the world. 'C++/CLI In Action' from Manning Publications is a good book. Regards, Duncan.

      --
      It is not immoral to create the human species - with or without ceremony, Samuel Clemens.
  42. Don't use pointer arithmetic? by wonkavader · · Score: 2, Funny

    - Avoid pointer arithmetic.

    But why use C++ if you're not using pointer arithmetic? If you're not doing that, go to Java. I know this sounds silly, and it opens religious issues, but (aside from legacy apps, like this one) why would I want to use C++ if I'm not doing that?

    I use C because it's small, fast, convenient and portable. I can code something tiny quickly.

    I use Java because it's an object oriented language that helps with complex app coding.

    I use C++ because I want some of that Java stuff, but I want it to bind to my memory model more realistically. ie. Pointer arithmetic.

    1. Re:Don't use pointer arithmetic? by geekoid · · Score: 1

      Speed.

      It sounds like he needs some very responsive code. No, it's not a flame, there is just something C++ can do better then Java.

      If it was some 'average' desktop app, yeah, go to Java. Writing an application that is moving bit's around in a hurry? Don't use Java.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    2. Re:Don't use pointer arithmetic? by sim82 · · Score: 1

      Valid point, but slightly overrated in my opinion.
      I just wrote some fairly low level scientific/numerical stuff in java (tons of array access mixed with floating point calculations, plus some preprocessing stuff with large bit-vectors (class BitVector from the colt library)) that is just as fast as the Fortran/C code it replaced. Of course this is only true for the newest java VM on fairly new intel/amd hardware. Also the algorithm seems to be relatively easy to optimize (drop array access checks etc.).
      On combination of IBM VM/Power4 hardware on the other hand the performance was, uhm, suboptimal to put it that way. (though I have not tested the Fortran/C version on that hardware)

    3. Re:Don't use pointer arithmetic? by tepples · · Score: 1

      But why use C++ if you're not using pointer arithmetic? Because it would be more work to port the Java virtual machine to a platform that does not already have it.
  43. Poor You by Anonymous Coward · · Score: 0

    Poor you. You raised on C++ and naturally feel no love. You get your memory screwed up. You have no good languages to program in. Worst of all, you're targeting XP.

    Poor you.

  44. Re:Don't allocate or free = no leaks = need no too by Anonymous Coward · · Score: 0

    We have seen some leaks in our applications. These were tracked down to STL internally leaking. They weren't generally very large and therefore we continue to live with them.

    Just FYI - what you most likely observed was not a memory leak. Various STL implementations will use their own pooled memory allocators where they won't release memory back to the free store so it can be subsequently reused for without the overhead of allocating the memory again.

    However, I've also run across a pathological case where perfectly valid C++/STL code did cause the gcc (something like v3.3 or v3.2) STL implementation to never reuse the memory it had allocated so eventually the process would drive the machine into swap until the OOM killer kicked in. I was able to confirm this be running the application for as long as I wanted to with the GLIBCXX_FORCE_NEW/GLIBCPP_FORCE_NEW environment variables defined.

  45. Use FORTRAN by clickety6 · · Score: 1, Funny

    ... or maybe COBOL or LISP... ;-)

    --
    ----------------------------------- My Other Sig Is Hilarious -----------------------------------
  46. Memory Validator by Gedalia · · Score: 2, Informative

    I have had pretty results from Memory Validator from Software Verify. (
    http://www.softwareverify.com/cpp/memory/index.htm l ) It'll slow down your app but I think it does a better job keeping things close to real time then purify.

    -----------
    Fight Entropy!!! Fight Entropy!!! Figth Etnropy! !
    iFgth Etnrop!y ! giFth tErno!py ! giFt htrEno!p y! --- Well maybe
    not...

  47. 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
  48. valgrind by nanosquid · · Score: 2, Interesting

    Use valgrind.

  49. SmartHeap by Anonymous Coward · · Score: 1, Informative
  50. shared_ptr thread safety by Anonymous Coward · · Score: 0

    > shared_ptr is not thread safe

    Not true, as I understand it (but please correct me if I'm wrong). See the section titled "thread safety" on this page: http://www.boost.org/libs/smart_ptr/shared_ptr.htm

        "shared_ptr objects offer the same level of thread safety as built-in types."

    It goes on to give various examples. This means that you only need to add your own locking in cases where you would also need to lock a built-in pointer type. Well, hmm.... a question that just occurs to me is whether a T* is small enough to be atomic on common architectures, while a shared_ptr is not atomic. It may be that code that relies on writes to pointers being atomic (which is true on most machines, but would not be on e.g. a 32-bit processor with a 64-bit address space) would not work with shared_ptr. But the rest of the time, I believe shared_ptr really is safe.

  51. Some Stuff For Roll Your Own Types by Anonymous Coward · · Score: 1, Informative

    The following CRT/Win32 functions can come in handy when diagnosing memory leaks and heap corruption.

    Use _CrtSetDbgFlag to get the memory manager to test the heap periodically during use among other things. Or use _CrtCheckMemory to do it strategically.

    Using _CrtMemCheckpoint and _CrtMemDumpAllObjectsSince can check to see if any heap blocks have been left on the heap in a range of code. You can use _CrtSetBreakAlloc to break on the allocation to locate the point where a widowed block was allocated.

    You can also use GetProcessHeaps and HeapValidate to check heap integrity. In particular, it can be used to check all heaps in the process.

  52. C++ errors suck! by Anonymous Coward · · Score: 1, Insightful

    Yes, absolutely true that error messages are useless. The blame for this can be shared between the language, the compiler, and the library. The worst I have encountered is Boost.Spirit where it would churn out messages hundreds of lines long with no clue whatever what the real problem was; you might as well just make random changes until the message goes away. In the end this makes you code in a very defensive style, not deviating far from the examples that you've copied-and-pasted from the documentation.

    I would say that this is a serious enough problem that we ought to stop and fix it before developing yet-more-complex libraries. One attempt to fix it at the language level is the introduction of 'concepts' in the next version of C++, which allows template classes to specify properties that their parameters must have - and which presumably allows more sane error messages when the properties do not hold. An attempt to fix it at the library level can be seen in the message that you cite: "property map not found". Yes, it's embedded in a load of stuff from the compiler, but maybe that's the best it can do.

    I'd be very interested to know whether any of the other compilers give more comprehensible error messages than g++.

  53. Purify by vorwerk · · Score: 1

    Rational Purify is probably the best tool on the market.

  54. Why make it more complicated? by HotBBQ · · Score: 1

    I understand the need for good C/C++ tools to check for memory leaks, performance bottlenecks, profiling, et cetra, but the idea of using garbage collection/memory management libraries in these languages seems a tad silly.

    1. Re:Why make it more complicated? by advs89 · · Score: 0

      "Why do drive-thru ATMs have Braille keypads?" So that a blind person doesn't have to tell his or her driver his or her pin number...

      --
      Rirelobql xabjf gung EBG-13 vf gur yrnfg frpher rapelcgvba rire, ohg jbhyq lbh jnfgr lbhe gvzr npghnyyl qrpelcgvat vg???
  55. GCC mudflap by MORB · · Score: 2, Informative

    If you can afford to make your app compile with mingw's gcc (or cygwin's gcc but mingw should be easier), then you may be able to use mudflap, which is a memory debugging system integrated into gcc. You just need to pass -fmudflap, and gcc will instrument the program at compilation time.

    One thing is that it used not to properly instrument some really basic C++ operation in gcc 4.1 (I don't remember what exactly, something like copy construction of an object containing pointers) and was reporting spurious leaks because of that. It may have been fixed in 4.2.

    Search for "mudflap" in the following page: http://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Optimi ze-Options.html#Optimize-Options
    As well as http://gcc.gnu.org/wiki/Mudflap%20Pointer%20Debugg ing (maybe slightly outdated)

  56. Re:Don't allocate or free = no leaks = need no too by HotBBQ · · Score: 1

    On the subject of garbage collectors, some of our colleagues use Java and .NET. Both sets of colleagues have had major performance problems caused directly by the garbage collectors kicking in and consuming vast CPU power while they did their thing.

    At the risk of being beaten into oblivion I would like to submit that often times when garbage collection causes a detectable performance penalty is due to poorly written Java code. The code generally looks more like C++ than it does Java. I am not saying that garbage collection is cost free, but can be effectively marginalized, even in large scale and high performance applications.

  57. Valgrind by Anonymous Coward · · Score: 0

    Valgrind is fantastic for something like this.

  58. Debugging heap issues by Anonymous Coward · · Score: 0

    Following MS tools are absolutely free:
    - Use umdh that is a part of the Debugging tools for windows to track memory leaks. http://www.microsoft.com/whdc/devtools/debugging/i nstallx86.mspx. Following article explains how to use it http://support.microsoft.com/kb/268343/en-us.
    - Whatever you do make sure you have proper symbols. Following article explains how to get symbols from MS symbol server. http://www.microsoft.com/whdc/devtools/debugging/d ebugstart.mspx
    - Use paged heap to track all other issue like memory overruns, double free and all other sorts of heap corruption. http://www.microsoft.com/technet/prodtechnol/windo ws/appcompatibility/appverifier.mspx
    - Please note that if you run you application with app verifier checks on you need to run it under a debugger. I would strongly suggest windbg or cdb instead of visual studio because it has extensions that would greatly help you to track down the issue ("!analyze -v" "!avrf" "!heap -p -a "). For more details see windbg help. If your application is a service then you might consider running your machine under kd, which would trap all unhandled exceptions and application verifier reports.
    - Following link has a very good windbg tutorial http://www.codeproject.com/debug/windbg_part1.asp.

    That is all you need to debug any kind of heap issues.

  59. Microsoft Application Verifier by ChriSindri · · Score: 2, Informative

    Application Verifier comes in x86, ia64 and amd64 flavors.

    This tool allows you to enable PageHeap for your process, which is heap corruption detection built into the OS heap implementation. Upon freeing a block of memory, PageHeap will break into your debugger spewing tracing that a block has been corrupted. It can also provide the call stack when the block was allocated. Newer heap validation features are available in progressively more recent OS releases.

  60. dmalloc by dannys42 · · Score: 1

    Unfortunately, I don't think it'll help you in the Windows world. But for *nix, I've found dmalloc to be quite simple to use but very effective.

    http://dmalloc.com/releases/

  61. Memory tracking tools for WIndows by Anonymous Coward · · Score: 1, Informative

    Following MS tools are absolutely free:
    - Use umdh that is a part of the Debugging tools for windows to track memory leaks. http://www.microsoft.com/whdc/devtools/debugging/i nstallx86.mspx. Following article explains how to use it http://support.microsoft.com/kb/268343/en-us.
    - Whatever you do make sure you have proper symbols. Following article explains how to get symbols from MS symbol server. http://www.microsoft.com/whdc/devtools/debugging/d ebugstart.mspx
    - Use paged heap to track all other issue like memory overruns, double free and all other sorts of heap corruption. http://www.microsoft.com/technet/prodtechnol/windo ws/appcompatibility/appverifier.mspx
    - Please note that if you run you application with app verifier checks on you need to run it under a debugger. I would strongly suggest windbg or cdb instead of visual studio because it has extensions that would greatly help you to track down the issue ("!analyze -v" "!avrf" "!heap -p -a "). For more details see windbg help. If your application is a service then you might consider running your machine under kd, which would trap all unhandled exceptions and application verifier reports.
    - Following link has a very good windbg tutorial http://www.codeproject.com/debug/windbg_part1.asp.
    That is all you need to debug any kind of heap issues.

  62. The best utility by far by Thomas+Charron · · Score: 1

    deleaker, from www.deleaker.com

    This is one of the best Windows C++ specific leak detectors out there. It is VERY simply to use, and integrates into Visual Studio in a very simple manner.

    --
    -- I'm the root of all that's evil, but you can call me cookie..
  63. Home brew tool for memory leaks with glibc by cant_get_a_good_nick · · Score: 3, Insightful

    GLIBC allows you to create hooks for the standard mem functions (malloc/realloc/free). Remember that g++ still calls these under new/delete so it works for C++ also.

    One of our guys coded up a simple shared lib that can be loaded with LD_PRELOAD that sets simple hooks of printing memory locations for new/realloc/delete. He then wrote a perl script that kept track of these things and spit out anything that was malloc'ed and not realloc'ed or free'd.

    I can't post it, because technically it's not my code it's my company's. But his shared lib code is just 300 lines long, and shouldn't be hard to duplicate. The perl log filter is even more straighforward. Each malloc gets saved. Each free removes the malloc. Each realloc removes the old malloc and adds a new one. Anything left over is a leak.

    Override __malloc_initialize_hook with a pointer to your init_function. In your init_function, save the old functions at __malloc_hook __free_hook __memalign_hook and __realloc_hook and substitute your own. Now write your replacement functions, in it, do your logging and temporarily replce the old hooks and call the original functions, replace with your hook on the way out to get the next call. All of the hooks should be wrapped in a mutex to help re-entrancy problems.

    It's not a full memory detector, just does leaks, but it's non-intrusive, requires no recompiles, and is the best way we have to leak detect our huge server long running code.

  64. Re:Don't allocate or free = no leaks = need no too by ivucica · · Score: 1

    So you think you're not allocating parts of that pool internally? Are you not marking pieces of the pool to be in use? Personally, much greater problem is buffer overrun than memory leaks. Memory leaks can be tracked, and fixed eventually. But how do you know where did a program do a buffer overrun? It's easy to see "aff, that was caused by a buffer overrun", but where?

  65. Debugging & Memory Tracking (VS2003+) by Mastadex · · Score: 0

    Microsoft has one of the best debuggers integrated into Visual Studio. It can find memory leaks and bugs in your code very easily and it just requires a couple of lines of code. you just surround all your code with the debugging function calls, and it will compare the before and after snapshots of your memory and tell you if you have a leak or not. Behold:

    #include <crtdbg.h>

    int main()
    {
      #ifdef _DEBUG
        _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF);
      #endif

      int *p = new int;

      #ifdef _DEBUG
        if (_CrtDumpMemoryLeaks())
        {
          printf("You have a Memory Leak!");
        }
      #endif
    }

    --
    A morning without coffee is like something without something else.
  66. Recent real world example by 2DGamer · · Score: 2, Interesting

    I can attest to this. A few months back I was doing cross development for FreeBSD/Linux and maintaining a development version for Windows.

    My code worked fine in Windows - mostly, but still a bug remained that I suspected was in the renderer but couldn't prove it.

    The code ran fine on FreeBSD without any problems but I couldn't run it for more that a few minutes on Linux without it crashing hard but at random times.

    I ran my Windows code through BoundsChecker (which I've used for years and have found to be very effective). Came up fairly clean, I fixed a few things but I could not find the bug.

    I wasn't familiar with any Linux debug tools but eventually tried Valgrind. It found the problem after the first run, and BoundsChecker didn't even give me a peep. I found I was stepping just outside a graphics buffer at certain times and writing in memory I didn't own. It was enlightening the bug was in the same code for FreeBSD/Linux/Windows but displayed completely different behavior.

    Anyway, I have respect for Valgrind. Now, if it was only available for FreeBSD.

    1. Re:Recent real world example by geniusj · · Score: 1

      It is available for freebsd. Check ports.

    2. Re:Recent real world example by TheRaven64 · · Score: 1

      The FreeBSD version doesn't have complete system call coverage. I was trying to use it to debug some code that made use of the POSIX AIO stuff. Oh, and the instructions on the site for adding new ones do not resemble the current code in any way. I got half way through adding aio_read, before I got bored and gave up working on undocumented code.

      --
      I am TheRaven on Soylent News
  67. stop being such a faggot by Anonymous Coward · · Score: 0

    and use Java

  68. TR1 by alexo · · Score: 1

    Partial implementation is available from Boost.
    A commercial full implementation can be purchased from DinkumWare.

  69. Re:Duh! by Anonymous Coward · · Score: 0

    Just replace that post with your own comment system, such as replacing God-awful with I'm, idiot with smart, disgust with inspire and stupid with curious. That results in: I'm simple you smart !! You inspire me that you are so curious !!
    Probably not what you were intending.
  70. Re:Don't allocate or free = no leaks = need no too by Speare · · Score: 2, Interesting

    I don't mind if an implementation of STL has some hidden/private/singleton allocation pools behind the scenes to speed things up. What I find really friggin' annoying is that they never track those allocations and offer any form of "reset" function that you can call before exiting your app, so that the simplest global malloc-counting methods can audit for leaks. You shouldn't need an "SGI-STL-aware-and-compatible leak detector," you should only need a malloc leak detector.

    --
    [ .sig file not found ]
  71. it's a dumb pointer by r00t · · Score: 1

    People screw up when they use this. Oh, maybe you're a genius who gets it right (just like you're a better than average driver) but have some pity on the other developers.

    You get leaks that aren't leaks. The memory gets freed when the app exits. That's useless, because the OS will free it then. What failed to happen was freeing while the app was busy doing stuff. It's not OK to have objects just hanging around, all tied to each other, until the app exits.

    You get bad interactions with regular pointers. Regular stuff gets leaked because you relied on the dumb pointers. Regular stuff gets double freed. Note: the regular stuff need not be pointers. It could be database connections, file handles, etc.

  72. Not reading is *another* of your problems. by Anonymous Coward · · Score: 1

    You've actually made several points here. I wonder if you realize how it looks for you to brag about taking almost a year As a person who has no apparent concept of what a man-year is, I sure hope your not in position to hire ANYONE.

    This is what I posted:

    and after watching the team flail and spend literally almost a man-year trying to find one memory bug, I finally had enough of "advice giving" being ignored Now, what part of '"advice giving" being ignored' is too complex for you to comprehend?
  73. MemDebug? by mytos · · Score: 1

    I had some problems with memory invasion and leaking in a game that I'm working. At that time I coded MemDebug.
    Its a pretty much simple memory debugger, detect leaks and comes with a pointer wrapper that detects memory invasion.

    You can get it here
    http://sourceforge.net/projects/memdebug

  74. Basically you are going back to Fortran mode by golodh · · Score: 1
    Basically your modus operandi takes you back to the good old Fortran ways of coding.

    I'll be the first to admit that static (as opposed to dynamic} array allocation is both quicker and less error-prone. Provided, as you already mentioned, that your application allows it. Your "pools" are what Fortran calls "shared common blocks".

    The problem that I see is that whenever you are re-using part of your "pools", you are in fact doing something akin to freeing and allocating memory as far as the statespace model of your software is concerned. Only you do it "internally", within the memory space allocated to you by the operating system.

    Of course you will avoid your programs crashing due to the operating system shooting them down for accessing memory that was not allocated to them, or from attempting to return memory to the operating system that the program doesn't "own" in the first place.

    This is essentially what memory-allocation and memory-freeing crashes amount to, but as far as I can see from the description you give, you can still commit grave "memory allocation" errors in that the variable you use at some place contains the data of some other variable. You just make sure that it happens where no operating system can possibly take offense. That doesn't necessarily mean that your code doesn't contain allocation/deallocation errors.

    If any such errors are present, your code will stay up and silently return the wrong answers. Is that an improvement? You be the judge.

  75. Insure++ from Parasoft by lordmage · · Score: 1

    Multi-platform, memory debugger with coverage analysis. It is NOT free and it works very well.

    There are several types of memory debuggers:
    source code,
    object code,
    linked library wrappers.

    Insure++ is Source Code instramentation. It wraps code with its own trap routines and finds a LOT of errors.
    Purify (I used it a bit ago, was not on Linux at the time) is a object code instramentation and it takes the object code and wraps it. It finds some stuff.
    Electric Fence is a FREE library that basically wraps malloc and traps some basic systems.

    Insure++ is the best that I have found. You can try it for a time if you wish at
    www.parasoft.com

    --
    I can program myself out of a Hello World Contest!!
  76. That doesn't even .... by IwantToKeepAnon · · Score: 0

    begin w/ "MZ", your Klingon must be rusty ad that would be an invalid EXEcutable.

    --
    "Happy families are all alike; every unhappy family is unhappy in its own way." -- Anna Karenina by Leo Tolstoy
    1. Re:That doesn't even .... by maxwell+demon · · Score: 1

      You want to look up the characters corresponding to the ASCII codes 77 and 90 :-)

      --
      The Tao of math: The numbers you can count are not the real numbers.
    2. Re:That doesn't even .... by inviolet · · Score: 1

      You want to look up the characters corresponding to the ASCII codes 77 and 90 :-)

      Yes, I chose those codes on purpose. Do you know what they mean, as the first two bytes of a wintel executable?

      --
      FATMOUSE + YOU = FATMOUSE
    3. Re:That doesn't even .... by maxwell+demon · · Score: 1

      You want to look up the characters corresponding to the ASCII codes 77 and 90 :-)

      Yes, I chose those codes on purpose. Do you know what they mean, as the first two bytes of a wintel executable?

      Yes. But did you check to which posting I actually answered? Hint: It was not yours.
      --
      The Tao of math: The numbers you can count are not the real numbers.
    4. Re:That doesn't even .... by IwantToKeepAnon · · Score: 0

      Ah yes, decimal. 077 and 090 say to me "octal".

      And yes, MZ was in my first (if errorenous) post.

      --
      "Happy families are all alike; every unhappy family is unhappy in its own way." -- Anna Karenina by Leo Tolstoy
  77. C++Builder 2007 includes CodeGuard by santakrooz · · Score: 1

    Just released today, C++Builder 2007 fully support Windows Vista and includes the tightly bound CodeGuard memory checker. CodeGuard will monitor overwrites, pointer usage, etc.

    C++Builder 2007 is the only C++ development environment that supports Windows Vista development (Visual C++ Orcas is still beta, might ship this year). But it supports Vista, XP, and 2000 all simultaneously. It's also the only RAD native compiling C++ development tool (Visual C++ is still MFC based... still uses resource files... not visual tools, components, or two-way designers).

    Check it out. http://www.codegear.com/products/cppbuilder

    1. Re:C++Builder 2007 includes CodeGuard by Anonymous Coward · · Score: 0

      Just released today, C++Builder 2007 fully support Windows Vista and includes the tightly bound CodeGuard memory checker. CodeGuard will monitor overwrites, pointer usage, etc.

      Prior versions at least through BCB5 also include CodeGuard, except the Standard/Personal editions. Sometimes you can find legal copies on eBay. The downsides are Windows-only and lagging ISO C++ support.

      - T

  78. Use a Garbage Collector by flyingfsck · · Score: 1

    The Conservative Garbage Collector http://www.hpl.hp.com/personal/Hans_Boehm/gc/ will make most memory issues go away. It is robust and is used in GCC for example.

    --
    Excuse me, but please get off my Pennisetum Clandestinum, eh!
    1. Re:Use a Garbage Collector by pfedor · · Score: 1

      An alternative approach to garbage collection in C++ (precise as opposed to conservative): Smieciuch.

  79. I probably used the wrong string class by Anonymous Coward · · Score: 1, Informative

    That example happened something like 5 or 6 years ago. Maybe try it on MSVC++ with CString?

  80. Re:Don't allocate or free = no leaks = need no too by etresoft · · Score: 1

    We are running many high speed financial message processing applications. A crash for any reason (including a leak) would be very costly for us.
    Leaks usually don't result in crashes unless they are severe or very long-lived. A more robust solution might be multiple, redundant, somewhat shorter-lived processes.

    Lastly, I strongly dislike anything from Rational. I find them overpriced unreliable bloatware (YMMV). Purify used to be good some time ago, but those days are long gone.
    IBM/Rational has bought up quite a bit of software over the years. Not all "Rational" software is equal. It is true that Purify is not going to help with an application such as yours that uses a memory pool. But for really big applications, with many developers (not all of whom are equal), Purify is just wonderful. It can, and will, track down leaks and other serious problems. When used with PureCoverage, it can give you confidence that your application doesn't, and won't ever, leak memory or crash
  81. Valgrind VS Purify by moltonel · · Score: 1

    If your app is already reasonably portable, consider porting to Linux solely to use Valgrind. It's that good. Otherwise, have you looked at Rational's Purify? I haven't used it myself but hear it has some pluses and minuses as compared to Valgrind, but is worth a look.

    I find valgrind invaluable; a lot of people swear by Purify instead. They sound like similar tools. I've never used the later but would love a comparison by somebody who's used both.

    What (think) I know :
    • valgrind is free, purify is proprietary
    • purify runs on some platforms that valgrind doesn't (BTW, I use valgrind on FreeBSD too)
    • purify requires to link your program with its library, valgrind runs unmodified binaries on a virtualized processor
    • valgrind has additional modules, like a profiler or a thread race condition detector
    What I'd love to know :
    • speed and memory usage
    • chances of detecting a bug
    • ease of use (including nifty GUIs if you want)
    • support for non-c/c++ languages
    • additional features
  82. Re:Don't allocate or free = no leaks = need no too by eison · · Score: 1

    Since JDK 1.4.1.something Java has shipped with multiple other memory management options specifically designed to minimize problems caused by stop-the-world garbage collection. Tell your colleagues to upgrade their JDK then activate the "CMS" garbage collector via command line switches.

    --
    is competition good, or is duplication of effort bad?
  83. But doesn't J2ME have RAM overhead? by tepples · · Score: 1

    just look up the phrase "j2me" for java runtimes designed for embedded devices. Will a game running in a J2ME virtual machine on a machine with 4 MB of RAM be able to keep track of as many simultaneous objects as a game written in C++ running on the same hardware?
    1. Re:But doesn't J2ME have RAM overhead? by Spy+Hunter · · Score: 1

      Yes, given a limited amount of time and equally skilled programmers, because they will be so much more productive not having to worry about tracking ownership and reference counting and wacky memory corruption crashes and writing custom allocators that they can use their limited time focusing on improving the algorithms being used, which is where the real wins are anyway.

      Given an unlimited amount of time to fix all the bugs and wring out all the performance, C++ will win. But in the real world, use Java and be done faster.

      --
      main(c,r){for(r=32;r;) printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}
  84. MemAnalyze by sklib · · Score: 1

    Here's a writeup on a tool someone wrote for this very purpose:

    http://www.gamasutra.com/view/feature/1430/monitor ing_your_pcs_memory_usage_.php?print=1

    --
    -S
  85. Re:Duh! by WrongSizeGlass · · Score: 1

    Yes, it was exactly what I intended. I was implying the poster was an asshat and wanted his meager intellect to be represented by his poor grammar and limited vocabulary. Surely I couldn't call him stupid and let him sound more than a dolt, could I?

  86. Give me a break. by Anonymous Coward · · Score: 0

    One man year - my ass. You actually fell for the bait of an AC's lie on Slashdot. You should feel ashamed of yourselves.

  87. LeakTracer (C++ only) by Anonymous Coward · · Score: 0

    Give LeakTracer a try. I uses LD_PRELOAD to avoid needing a recompile, and hooks into the new and delete operators to provide a concise leak report.

  88. Application Verifier by alex288 · · Score: 1

    Microsoft's Application Verifier is a great tool for diagnosing lots of problems (on Windows mind you) including doing verification on your not overflowing bounds. Best part is you don't even have to change your code or recompile, it does completely run-time diagnostics. http://www.microsoft.com/technet/prodtechnol/windo ws/appcompatibility/appverifier.mspx For the memory validation, every time you allocate memory it'll put it in it's own page with guard pages around it such that if you write past your buffers even by a single byte you'll immmediately AV inside the offending code (rather than crashing later on in some unrelated code or inside the heap manager). Dead simple to use, and has saved me countless hours. A similar tool is the Driver Verifier, which is actually included with most releases of Windows under C:\Windows\System32\verifier.exe. It does essentially the same kinds of things but for drivers, so if you've been getting lots of blue screens with stuff like BAD_POOL_HEADER etc, run verifier, wait a few minutes for the driver to do it's dirty deed, and take a look at the crash dump to see which driver is to blame.

  89. AppVerifier by Anonymous Coward · · Score: 0

    AppVerifier will do memory stuff as well as a few other things.

    http://technet.microsoft.com/en-us/library/bb45706 3.aspx

  90. Valgrind is king by Amrik · · Score: 1

    I've used Purify, Boundschecker, Efence, various hand-rolled stuff and by far the best tool for checking memory access and for leaks is Valgrind. Because of the way it works, it finds all sorts of tricky memory problems at the point that they happen without *any* instrumentation of your program before hand.

    The downside is that it only works on linux (and x86 at that), but it kicks ass. It's one of the unsung heros of open source.

    Try if you can.

  91. Memory Checker by A+Nun+Must+Cow+Herd · · Score: 1

    We also found BoundsChecker to be too slow to be very useful. AQTime (AutomatedQA), on the other hand, is relatively cheap and fast. There's a full featured (time limited) trial version that you can download.

  92. auto_ptr by JustNiz · · Score: 1

    There are many many references all over the internet for why using auto_ptr (which is boost's shared_ptr) is philospohically a bad idea.

    Ultimately it comes down to being careful when you write your code that you clean up. There are a few things you can do to help:
    1) Use containers wherever possible rather than create clouds of dynamically created objects.

    2) Don't expect the user of your function to know to clean up after you, even if the user of your function is you. (e.g. pass in an empty container as a parameter that the function fills, rather than dynamically create/populate memory in the function then return it). This approach also helps reduce the number of calls to malloc()/new() as the caller can statically create an empty container.

  93. If step 1 is "port the JVM" by tepples · · Score: 1

    Yes, given a limited amount of time and equally skilled programmers

    How hard is it for these "equally skilled programmers" to port the J2ME runtime environment to a platform that has never seen Java before? How hard is it for them to do so and make a game in Java vs. to make a game in C++?

    If you haven't guessed, the platform in question is Nintendo DS.

    1. Re:If step 1 is "port the JVM" by Spy+Hunter · · Score: 1

      That certainly does tilt the balance in favor of C++. It doesn't make sense to port the entire runtime and create appropriate tools and libraries for just one project. If Nintendo provided a Java environment, or if you could reuse the base for tens of projects, that would be a different story. I'm kinda surprised that nobody has ever tried to run Java on the DS. After all, a lot of games are being written in Java now for phones.

      --
      main(c,r){for(r=32;r;) printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}
  94. Re:Don't allocate or free = no leaks = need no too by Anonymous Coward · · Score: 0

    Why is everybody so obsessed with doing things manuallly? Why do you insist on creating your own private memory allocation instead of addressing the root problem? Doing allocation yourself just makes the whole thing more complicated, and makes your code even more prone to bugs.

    Screw memory allocation. Ban pointers. Just allocate everything on the stack, forget the heap. Pass by value instead of reference. If you are working within a single thread, use references freely, just never pointers. If you are multi-threaded, use established and well-tested message passing systems instead of pointers to objects on the heap (or, God forbid, the stack!).

    It is entirely possible to write low-memory and highly-performant systems by eschewing pointer use. In fact, it allows the compiler much greater flexibility in optimization because all the zillions of problems with aliasing vanish, making ambiguity almost non-existent.

    Why does everybody assume without question that pointers are the only way of writing quality C++ code?

  95. Fortify by GlenMac · · Score: 1

    I don't know if you've used or seen fortify but I found it a wonderful tool to not warn and resolve memory issues in C++.

    It is very fast, compiles switches into nothing and incredibly helpful.

    -- Snip
    Fortify is a powerful C++ debugging aid. Detects and pinpoints memory related bugs. It supports alloc/calloc/realloc/strdup/free and new/delete. It traps memory leaks, writes beyond and before memory blocks, writes to freed memory, free twice, freeing memory never allocated, and removes all randomness from reading uninitialized or free memory.

  96. Are you thick or what? by Viol8 · · Score: 1

    Not just where its defined, where its used! Try grepping for a "+" in any significant program!

    1. Re:Are you thick or what? by maxwell+demon · · Score: 2, Insightful

      Why should I ever have to do that? Either I'm checking the correctness of operator+, then I'm interested in the implementation of it, and don't care at all about who might call it where for whatever reason. Or I'm checking the correctness of code which uses operator+, and then I already know where it is used (in the code I'm checking right now, and I don't care it it is called from anywhere else).

      Indeed, with generic programming, the same code may call several different implementations of operator+, depending on what type it is used on. The same goes BTW for normal named functions. And the same is also true for virtual member functions (operator or not) in an OOP context.

      I'd say if you have to find the callers of operator+ in order to check if it is implemented correctly, there's something fundamentally wrong with your code.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    2. Re:Are you thick or what? by Viol8 · · Score: 1

      "Why should I ever have to do that?"

      Oh I dunno , because you've changed the implementation and need to know where in the program its used so you create suitable tests? Just a wild guess.

    3. Re:Are you thick or what? by feronti · · Score: 1

      You should already have the test cases, and if the other places it's being used depend on the broken behavior _their_ test cases should now fail.

    4. Re:Are you thick or what? by Viol8 · · Score: 2, Insightful

      Meanwhile , back in the real world...

    5. Re:Are you thick or what? by Anonymous Coward · · Score: 1, Insightful

      "Why should I ever have to do that?"

      Oh I dunno , because you've changed the implementation and need to know where in the program its used so you create suitable tests? Just a wild guess.


      Oh, come on, really? You didn't immediately think of searching for the name of the class on which operator+ is overloaded? The class name will appear in the function parameters or the local variable declarations for code where the unit tests might need to be examined. Given that hint, you should be able to think of where else you might need to look for the class name. If you cannot handle that, consider sticking to that language where "&" is used for string catenation, as you noted elsewhere. Presumably you were referring to VB6 or earlier?

      - T

  97. D language by yk4ever · · Score: 1

    Not directly related to your problem, but just FYI...

    http://www.digitalmars.com/d/index.html - D language, free, memory-managed and compiles to native code. Perhaps worth checking out.

  98. rtti by Corngood · · Score: 1

    All they would need is a more robust run-time type information system. Something more along the lines of reflection in .Net would be amazing (as long as it's optional for the core language). I would love something like that to help automate serialisation, garbage collection, inter-language interfaces, etc. That, and a fancy multipass compiler to get rid of headers and the order of definition nonsense are on my wishlist.

    I think for either to succeed though, you'd need to build them as a frontend for existing C++ compilers, instead of waiting for support.

    1. Re:rtti by MenTaLguY · · Score: 2, Informative

      All they would need is a more robust run-time type information system.

      No, not at all. The current C/C++ specifications permit compilers to transform code in ways that can interfere with a garbage collector. Fortunately compilers do not do that as often as they could, but it seems like something important that should be addressed.

      See Hans' paper Simple Garbage-Collector Safety for details.

      --

      DNA just wants to be free...
  99. GC is good, but relocation +GC is better by Anonymous Coward · · Score: 2, Insightful

    I was a developer for a "top 5" web browser for 6 years. I often worked on porting to small platforms and I also focused on how to improve performance on these platforms.

    Before I go into a rant, I must first rant about how much I hate Java. I feel that it was a great proof of concept and that they should have taken what they learned and went back and did it better. Java is a lot of great ideas implemented poorly due to lack of experience. I think they should have spent more time with the SmallTalk guys who actually almost had it right to begin with. Hell, evolving SmallTalk would have been far more intelligent than turning C++ into SmallTalk.

    Ok... here's the thing. I tried a lot of competing products. I tried memory checkers, memory allocators (and SmartHeap is the shit!), I tried memory profilers, hand instrumented memory logging, etc... what I've learned are a few things...

    Garbage collection (even reference counting) can improve performance greatly, but it had little or no impact on fragmentation. A system that I slapped together as a malloc/free new/delete override proved quite successful at drasticly improving browsing performance. What I did was that instead of deleting memory, I queued deletes and when the pool needed to be grown, I would process the deletes or I would process the deletes during idle cycles.

    This just made the program seem faster during runtime... obviously, the added overhead just made it slower.

    To explain why a web browser is one of the most rigorous tests of a memory environment... just think of the hundreds to thousands of DOM nodes/elements/etc..., script objects, images, etc... there are in sinlge page. Add that each element is typically represented by a single allocated object. Consider that images can decode to 100 megs in size (yes, it happens), most often closer to 2-3 megs for background images.
    A web browser can't use a memory system optimized for specific object sizes.
    Due to the dynamic nature of the objects, object reusability is not really an option
    Scripts can grow or shrink memory usage thousands of times per second
    Browsers typically contain 3rd party code from plugins which need to interact with the browser

    I can go on and on... a web browser is possibly the worst memory management nightmare on the planet. Often I worked with customers that were developing their own operating system. They used to tell me that my web browser must suck because making it stable on their system was a pain in the ass and often required them to either change or rewrite their entire memory management system to get good performance on embedded devices. Then I'd explain to them that up until now, their memory manager has been having a friendly snow-ball fight with a penguin, now it's running for it's life from an avalanch caused by a mean Yeti.

    So here's the deal, GC really didn't pay off for us... helped a little, but I have to say that once we started using reference counting and simple GC, the quality of the code got really poor. Just look at Symbian for an example of a product that suffers from using great memory management system that increases coding complexity 10 fold. It makes it so that you spend all your time coding for the memory manager and you run out of time to make the program itself work.

    Now on the other hand, I played with a few Java web browsers and learned something important. Java is made for phones. If it has no other purpose (and I'm convinced it doesn't), it's for embedded devices. Because of relocatability, fragmentation doesn't occur (in a good VM) and applications run much better. The GC + Relocation system is REALLY REALLY REALLY good, if I were to start writing a new web browser today, I'd find a good alternative to Java and get moving on it.

    Oh... last thing about auto-pointers, they're a blessing and a curse. For the most part, I find the best solution to be to use a proper system library like Qt instead of boost or STL. Qt seems to actu

  100. Live on the stack by gatkinso · · Score: 1

    Avoid heap allocation if at all possible.

    Not an end all cure, and won't help in the cases where you absolutely NEED dynamic allocation... but as a practice you will find this to greatly decrease your memory woes.

    When a junior dev shows me C++ code using pointers I tell him to rethink his implementation so that it doesn't use pointers.

    In the hands of a master pointers an dynamic memory allocation are great.... but judging by the way everything seems to leak and leak copiously there are very few "masters" out there.

    --
    I am very small, utmostly microscopic.
  101. Google Heap Leak Checker by pfedor · · Score: 1

    The tool created at Google and released as open-source: http://google-perftools.googlecode.com/svn/trunk/d oc/heap_checker.html

  102. Re:Don't allocate or free = no leaks = need no too by Anonymous Coward · · Score: 0

    Try a static analysis tool like Coverity... http://scan.coverity.com/

  103. Re:Don't allocate or free = no leaks = need no too by Verte · · Score: 0

    Sounds like what you need is actually an obstack. These come with glibc.

    --
    We at slashdot are scientists, specialists and kernel hackers. Your FUD will be found out.
  104. The Sunk Cost of Ugly by tjstork · · Score: 1

    True... but, the thing is, there are a lot of systems out there where the code is ugly, but, mostly works. Sure, it is less expensive to design a system right the first time around, but what often happens is that the system is well designed, but the company has already spent a giant chunk of money on all the testing needed to overcome the bad design. So yeah, you have a bad system, but one that does work. In their eyes, a rewrite is to incur the risk of going back to the beginning of a project. For everyone that rolls those dice and gets a clean, well designed system, there's another couple that get more delays brought on by a design as bad as the original one was to begin with, just in different ways.

    While it is true that 90% of the cost of a program is in "maintenance", a lot of time, maintenance is a much smaller team than the original development team was. You can quickly go from a dozen developers down to 2, so, from a budget perspective, that doesn't seem so bad. Maintenance too, is often an addition of features and screens and tables. You aren't rewriting or refactoring existing code as much as you are tweaking it to allow for the big new thing to work. In the end, you can put your "good design" into your new stuff, and leave the old stuff alone. Then, the next guy comes along and puts his "good design" in. Quite often you wind up with a project that has a number of different personalities to it.

    --
    This is my sig.
  105. If you can't beat em, join em. by Meor · · Score: 0

    Replace *alloc with a garbage collection library and forget manual memory management. Arguing manual memory management versus garbage collection is like arguing 2^n versus 128*n Yes in a small area and for a period of time you can manage memory collection manually, the problem comes after your application has matured and you're a year down the road(n = 11) Now it's more complex to manage from a human standpoint and often slower in terms of CPU and memory footprint to manage reference counts. First rule of optimization, find a better algorithm.

  106. A modest suggestion by DoofusOfDeath · · Score: 1

    These newfangled memory-managed languages like Java and C# leave an old C++ dev like me feeling like I am missing the love.

    Maybe it's time to switch over to one of these newfangled memory-managed languages? It's a tiny bit like saying, "My Pinto is a huge death trap! Anyone know of some after-market air-bag kits for it?"

  107. It depends on the audience by p3d0 · · Score: 1

    I think I speak for many programmers when I say ... Having a full function name (and real variable names instead of v1 and v2) would make it much more clear what is actually going on. But if your code is going to be read by more mathematicians than programmers, you'd better write it their way.
    --
    Patrick Doyle
    I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
  108. OT: Flamebait by Anonymous Coward · · Score: 0

    You live, ideally you learn
    Unless you're part of the Bush administration.
  109. Re:Don't allocate or free = no leaks = need no too by canuck57 · · Score: 1

    We pre-allocate pools of objects at startup and then re-use them. ...

    I knew when I read that I was reading an intelligent post. Your application probably even runs faster too, not having to do all the new/delete or malloc/free or that real slow system choking GC stuff.

    I first did this with embedded systems that had to be up for a very long time and memory leaks were just not an option. Pre-allocation stopped it. Always use this method of design when practical. When not, I am careful with memory management and create a special object class to track it.

    But looking at the posts in this thread, I guess there is a shortage of seasoned and skilled C/C++ programmers with regards to memory management. I have yet to see a 100% capable tool for this issue. Either it misses it, takes too long, or more often gives so many false positives it is useless.

  110. On a handheld? by tepples · · Score: 1

    They were when 486s were king but these days, the gap (what desktop computes can do versus can't in a reasonable window) is so large, it's just not a concern with discusion unless you have legitimate reason to raise it. Here's your legitimate reason: Handheld computers have much smaller CPUs and much smaller memories than desktop computers.
  111. Port to PC and use Valgrind? by tepples · · Score: 1

    Valgrind is nice - I'd like to use it but I couldn't find support for the arm platform. Could you have maintained a port of your application to the PC and run Valgrind on that like thaig did?
  112. Is CPU/memory cheap for 1000 customers? by tepples · · Score: 1

    as we all know startup time is the only relevant performance metric, and Java is primarily used to run applets. On the desktop, this is more true than some fanboys of the Java platform would like to admit.

    2. CPU/memory is cheap compared to paying programmers, especially if your app runs only serverside. Even if it has to run on 1000 different servers owned by 1000 different customers? Or are you talking only about bespoke development for one customer?
  113. Reboot? by tepples · · Score: 1

    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. So should all programs be divided into two processes, one that can run on Linux and one that cannot run on Linux because it requires APIs such as QuickTime or Windows Media that are not ported to Linux, with the two processes communicating over the network? And how often should a programmer have to reboot his machine to switch operating systems just to run Valgrind?