Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > RAII (Resource Acquisition Is Initialization) pattern limitations

Reply
Thread Tools

RAII (Resource Acquisition Is Initialization) pattern limitations

 
 
George2
Guest
Posts: n/a
 
      12-26-2007
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
 
Reply With Quote
 
 
 
 
Barry
Guest
Posts: n/a
 
      12-26-2007
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Why is RAII called RAII? Johannes Schaub (litb) C++ 2 09-18-2010 09:18 AM
Re: Why is RAII called RAII? Goran Pusic C++ 11 09-16-2010 03:11 PM
Re: Why is RAII called RAII? cpp4ever C++ 1 09-13-2010 06:25 AM
RAII for value objects Markus Elfring C++ 23 01-27-2005 08:41 PM
RAII / handling failures during destruction - advice required MikeB C++ 4 10-26-2004 05:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57