RAII (Resource Acquisition Is Initialization) pattern limitations

Discussion in 'C++' started by George2, Dec 26, 2007.

  1. George2

    George2 Guest

    Hello everyone,


    Through my testing and study of RAII (Resource Acquisition Is
    Initialization) pattern, I think it can solve resource release issue
    in the following two situations,

    1. Local function object (on stack);
    2. Object (either on heap or stack) pointer by auto_ptr;

    But it has the limitation that the object pointed by a normal pointer
    and allocated on heap (using new or new[]) can not be automatically
    released, either the function returns normally or during exception
    stack unwinding. Is that correct?


    thanks in advance,
    George
    George2, Dec 26, 2007
    #1
    1. Advertising

  2. George2

    Barry Guest

    George2 wrote:
    > Hello everyone,
    >
    >
    > Through my testing and study of RAII (Resource Acquisition Is
    > Initialization) pattern, I think it can solve resource release issue
    > in the following two situations,
    >
    > 1. Local function object (on stack);
    > 2. Object (either on heap or stack) pointer by auto_ptr;
    >


    The name of this idiom literally suggests such usage, and of course the
    "limitation"

    > But it has the limitation that the object pointed by a normal pointer
    > and allocated on heap (using new or new[]) can not be automatically
    > released,


    do you mean GC?

    either the function returns normally or during exception
    > stack unwinding. Is that correct?


    if you returning an auto_ptr, there's no such issue, as copy constructor
    of auto_ptr guarantees no throw.
    anyway, I still not quite understand what you mean.
    Barry, Dec 26, 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. yang su
    Replies:
    11
    Views:
    577
    Rolf Magnus
    Aug 10, 2004
  2. Johannes Schaub (litb)

    Re: Why is RAII called RAII?

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

    Re: Why is RAII called RAII?

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

    Re: Why is RAII called RAII?

    Goran Pusic, Sep 13, 2010, in forum: C++
    Replies:
    11
    Views:
    532
    ptyxs
    Sep 16, 2010
  5. Replies:
    3
    Views:
    90
    Paul Brannan
    Sep 4, 2007
Loading...

Share This Page