RAII Design Patterns and Alternatives

Discussion in 'C++' started by JohnQ, Mar 10, 2007.

  1. JohnQ

    JohnQ Guest

    Scenario: A GUI program is developed such that the startup sequence is
    controlled by the instantiation of a key object which instantiates other
    objects etc. until it finally arrives at the point where it is waiting in
    the message loop for messages to be put in its queue.

    That is, unless something goes wrong during one of those object
    instantiations in the program startup processing! Say somewhere in the
    middle of all that startup processing, something does go wrong. Well, if the
    objects were built with the RAII/exception architecture, the stack would
    unwind back to the catch point. At which point, just maybe, an error would
    be logged and the program would abort.

    Or maybe, knowing that the OS is going to clean up resources for us when the
    program aborts, maybe it is a lot simpler just to program the objects so
    that they log and abort (sans exceptions) whenever they encounter error.

    Whaddaya think?

    John
     
    JohnQ, Mar 10, 2007
    #1
    1. Advertising

  2. JohnQ

    Phlip Guest

    JohnQ wrote:

    > Or maybe, knowing that the OS is going to clean up resources for us when
    > the program aborts, maybe it is a lot simpler just to program the objects
    > so that they log and abort (sans exceptions) whenever they encounter
    > error.
    >
    > Whaddaya think?


    Write code ready to be refactored and upgraded. That means never rely on the
    Memory Fairy today, if tomorrow a given method might move inside a loop, and
    then cause a runaway leak.

    --
    Phlip
    http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
     
    Phlip, Mar 10, 2007
    #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. crichmon
    Replies:
    4
    Views:
    499
    Mabden
    Jul 7, 2004
  2. Tim Smith
    Replies:
    2
    Views:
    867
    Tim Smith
    Dec 15, 2004
  3. Johannes Schaub (litb)

    Re: Why is RAII called RAII?

    Johannes Schaub (litb), Sep 12, 2010, in forum: C++
    Replies:
    2
    Views:
    411
    James Kanze
    Sep 18, 2010
  4. cpp4ever

    Re: Why is RAII called RAII?

    cpp4ever, Sep 12, 2010, in forum: C++
    Replies:
    1
    Views:
    418
    BGB / cr88192
    Sep 13, 2010
  5. Goran Pusic

    Re: Why is RAII called RAII?

    Goran Pusic, Sep 13, 2010, in forum: C++
    Replies:
    11
    Views:
    569
    ptyxs
    Sep 16, 2010
Loading...

Share This Page