[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Constructors, Destructors and Resource Management

ebony.soft

10/8/2008 9:18:00 AM

Dear all
Hi
As you know constructor is a member function with several missions and
one of them is "acquiring a resource" and in the same token destructor
"releases the resource". Usually after such descriptions, It is said,
the resource is like memory, file, lock, semaphore, ... As a matter of
fact, resource isn't confined to memory and constructor/destructor do
more than just memory management. I reviewed most of the major books
and papers about C++, but I can't find good examples of untrivial
resource management like lock, semaphore.
would you please make some examples for untrivial resource management.
Do you know the systems/codes/papers that describe such things?

Regards
Saeed Amrollahi
1 Answer

Maxim Yegorushkin

10/8/2008 1:06:00 PM

0

On Oct 8, 10:17 am, ebony.s...@gmail.com wrote:


> As you know constructor is a member function with several missions

Constructor has but one purpose, which is to initialise an object.
What exactly constitutes initialisation depends on the nature of the
object.

> and
> one of them is "acquiring a resource" and in the same token destructor
> "releases the resource". Usually after such descriptions, It is said,
> the resource is like memory, file, lock, semaphore, ... As a matter of
> fact, resource isn't confined to memory and constructor/destructor do
> more than just memory management.

IMHO, Resource Acquisition Is Initialisation (aka RAII) is a misnomer
because it does not really matter whether a resource is acquired in
constructor or later on. What does matter is that the resource is
released in the destructor.

> I reviewed most of the major books
> and papers about C++, but I can't find good examples of untrivial
> resource management like lock, semaphore.
> would you please make some examples for untrivial resource management.
> Do you know the systems/codes/papers that describe such things?

http://www.boost.org/doc/libs/1_36_0/doc/html/t...
http://en.wikipedia.org/wiki/C_0x#Threading_...

--
Max