Re: Memory Management scares me

Discussion in 'C++' started by hondacivic@whoever.com, Apr 1, 2004.

  1. Guest

    Thore Karlsen <> wrote in message news:<>...

    > Memory management is typically very simple in C++. You just need to know
    > how to do it right, but once you see the right way to do it you'll
    > understand how easy it is.


    Although I don't disagree, and have written tons of clean software in
    C++ in the past, I now write almost exclusively in Java, because in
    Java it is even easier.

    > The trick is never to use raw pointers.
    > Always use smart pointers or classes like vector.


    I think that would make C++ actually slower than Java.

    > There is very rarely a need for raw pointers. I almost never need them.


    But other people in the development team will, and the project risks
    getting canned by the company.

    > In the product I'm responsible for I have had a couple of memory leaks.
    > Almost all were caused by buggy Microsoft components/APIs that I had to
    > work around, and one was caused by another third-party component.


    I remember BoundsChecker, oh no, it's all coming back now.

    > I haven't had a single memory leak caused by my code in any of the
    > applications I'm responsible for, not even in beta code. If you avoid
    > raw pointers, which you can in almost all circumstances, you just never
    > have to worry about memory leaks.


    Perhaps. I can write clean code too. But I think these days, one
    needs too many excuses to stick with C++. Stroustrup is way passee,
    although I used to, and still do to some degree, admire his thinking.
    His Java dismissal was too much of a turn off. I bet me against him
    writing an app from scratch, he wouldn't have a hope in hell
    competing.

    > I also use smart pointers and wrapper classes for other resources, so
    > there's no need to manually clean up those either. In fact, it is harder
    > to do this correctly in Java for non-memory resources since Java doesn't
    > have deterministic destruction.


    And then you spend a lot of time inventing a method of organizing,
    hard for other people to get on board with. Each 'good' software
    architect tends to build a proprietary foundation in C++. Bad for
    companies and teams. In java you write libraries too, but you spend
    less cycles at the *really* low level.

    > Even initialization and cleanup of libraries is much easier in C++.
    > Example using a scope guard:
    >
    > JPEG_CORE_PROPERTIES jprops;
    > if (ijlInit(&jprops) != IJL_OK)
    > return E_FAIL;
    >
    > ON_BLOCK_EXIT(ijlFree, &jprops);
    >
    > No matter what happens below this, ijlFree() will always be called. You
    > can return anywhere, throw an exception, whatever -- jprops will be
    > freed automatically.


    With Java's generational garbage collector, you can expect that as
    soon as an object or group of objects become isolated, they get
    cleaned up.
    As for closing resource and files, there's the finally thing, not
    object's finalize, which has been taboed, but the try{}finally{}.

    > C++ has an undeserved reputation for being tricky in this area, when
    > it's really one of the easiest languages to do the right thing in.
    > Sadly, judging by the bugs I see and the code I've looked through, few
    > people seem to know how to use C++ properly.


    Which is why C++ performs poorly in teams.

    Check out these GC related pages:
    http://www-106.ibm.com/developerworks/java/library/j-jtp01274.html
    http://java.sun.com/docs/hotspot/gc1.4.2/faq.html
     
    , Apr 1, 2004
    #1
    1. Advertising

  2. wrote:

    Let me guess. You work here:

    http://www.can.ibm.com/torontolab/


    > Although I don't disagree, and have written tons of clean software in
    > C++ in the past, I now write almost exclusively in Java, because in
    > Java it is even easier.


    I suspect GC will be a fairly standard /option/ for C++ in the not too
    distant future. So this may turn out to be moot.

    > I think that would make C++ actually slower than Java.


    I'd like to see the numbers. And the source used to produce them.


    > But other people in the development team will, and the project risks
    > getting canned by the company.


    There are coding standards, and there may even be ways to lint code for such
    things. I'v proposed creating a 'safe' mode subset of C++ which would
    confine code within a carefully chosen syntactic limit. Other's haven't
    been too kind to the idea, but don't count it out.

    >> In the product I'm responsible for I have had a couple of memory leaks.
    >> Almost all were caused by buggy Microsoft components/APIs that I had to
    >> work around, and one was caused by another third-party component.

    >
    > I remember BoundsChecker, oh no, it's all coming back now.


    I remember Microsoft...It's all coming back to me now...

    > Perhaps. I can write clean code too. But I think these days, one
    > needs too many excuses to stick with C++. Stroustrup is way passee,
    > although I used to, and still do to some degree, admire his thinking.
    > His Java dismissal was too much of a turn off. I bet me against him
    > writing an app from scratch, he wouldn't have a hope in hell
    > competing.


    Do you start from scratch with the core language as defined in the Java
    Language Specification, or are you throwing in all the other stuff such as
    Swing, javax.net.*, etc.? Can he then use freely available counterparts
    from open source? I'm not going to place bets. A language designer may
    not be the fastest coder. I'll bet Stroustrup could show you up in terms
    of core contributions to computer languages.

    For me, I am much faster with Java. But I'm still trying to find my feet in
    C++. There is a lack of Linux tools for C++ comperable to JBuilder, and I
    also believe there are some infrastructure issues involved with C++.


    > And then you spend a lot of time inventing a method of organizing,
    > hard for other people to get on board with. Each 'good' software
    > architect tends to build a proprietary foundation in C++. Bad for
    > companies and teams. In java you write libraries too, but you spend
    > less cycles at the *really* low level.


    The C++ community has been slow to address the need for common resources,
    but they're comming around. For example http://www.boost.org

    > With Java's generational garbage collector, you can expect that as
    > soon as an object or group of objects become isolated, they get
    > cleaned up.
    > As for closing resource and files, there's the finally thing, not
    > object's finalize, which has been taboed, but the try{}finally{}.


    Got any benchmarks we can contest, uh, I mean examine?


    > Which is why C++ performs poorly in teams.


    Not in all cases. http://www.kde.org

    One thing to consider with C++ is that there are a _lot_ of experienced
    people who /can/ contribute to the kinds of infrastructure that gives Java
    some advantages. I hope C# is a wakeup call to them. Microsoft has a new
    baby, all their own. Remember OS/2 and the original plans for NT?

    This is actually what inspired me to start this thread. Friends of your's?

    http://xml.apache.org/xerces-c/apiDocs/classXMemory.html

    :-D

    --
    p->m == (*p).m == p[0].m
    http://www.kdevelop.org
    http://www.suse.com
    http://www.mozilla.org
     
    Steven T. Hatton, Apr 1, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. penguinista

    Embeded perl & memory management

    penguinista, Jun 30, 2004, in forum: Perl
    Replies:
    0
    Views:
    618
    penguinista
    Jun 30, 2004
  2. Floris van Haaster

    Project management / bug management

    Floris van Haaster, Sep 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,252
    Jon Paal
    Sep 23, 2005
  3. pouet
    Replies:
    2
    Views:
    783
    Will Hartung
    Jul 30, 2004
  4. Matt Oefinger
    Replies:
    0
    Views:
    223
    Matt Oefinger
    Jun 25, 2003
  5. Richard Gration

    Perl scares me ...

    Richard Gration, Apr 27, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    108
    Joe Smith
    Apr 28, 2004
Loading...

Share This Page