473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

RAII (Resource Acquisition Is Initialization) pattern limitations

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
Dec 26 '07 #1
1 1300
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.
Dec 26 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pierre Rouleau | last post by:
As much as I love Python, I sometimes find myself wishing Python supported the RAII idiom (resource acquisition is initialization) that is available in C++, the emerging D language, and others. ...
26
by: codymanix | last post by:
Last night I had several thought about RAII and want to discuss a bit. Why doesn't CSharp support destructors in structs? Wouldn't that make RAII possible like in C++? When the struct goes out of...
11
by: yang su | last post by:
I have a very simple program listed below, which basically tries to use resources but prevent from memory leak should exception occurs. class T is the resource and class User is to use the...
4
by: MikeB | last post by:
Hi, Recently I was asked to look at some code where RAII is used to ensure automatic cleanup of a resource. Unfortunately, cleaning up the resource requires that the destructor make a call...
23
by: Markus Elfring | last post by:
The class "auto_ptr" implements the RAII pattern for pointer types. It seems that an implementation is not provided for non-pointer values by the STL so far. I imagine to use the "acquisition" for...
5
by: Nick Keighley | last post by:
Hi, In the beginning the code was:- BRUSHH new_brush = create_brush() BRUSHH old_brush = select_brush (new_brush) draw(...) select_brush (old_brush) destroy_brush (new_brush)
6
by: tomthemighty | last post by:
A simple RAII wrapper for acquiring a Thingy that has two alternative acquire methods, acquire() and acquireAndFurtle(): class ThingyAcquirer : private boost::noncopyable { public: explicit...
3
by: George2 | last post by:
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...
1
by: George2 | last post by:
Hello everyone, I think unmanaged resource means the resources (e.g. memory and file handler) which is used directly (new, FILE*) other than using a wrapper class (Resource Acquisition Is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.