Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , ,

Sponsored Links



C++ : Resource Acquisition is Initialization

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 27-01-2010
Member
 
Join Date: Jan 2010
Posts: 21
C++ : Resource Acquisition is Initialization

How are you all??? I had just started to learn the C++ language. Today my C++ teacher ask me about the Resource Acquisition is Initialization. But I don't know about the Resource Acquisition is Initialization. So, I could not able to give the answer of the question. So, I would like to about the Resource Acquisition is Initialization and what is the actual meaning and purpose of Resource Acquisition is Initialization in C++ language. So, Can anyone help me to know about the Resource Acquisition is Initialization?
Reply With Quote
  #2  
Old 27-01-2010
Member
 
Join Date: May 2008
Posts: 1,990
C++ : Resource Acquisition is Initialization

Resource Acquisition is Initialization or short form of it is RAII. Resource Acquisition is Initialization is a term that is closely related with automatic garbage collection and exception handling. Resource Acquisition is Initialization can be known as the method or technique of performing all necessary resource initialization work right from inside the body of the constructor itself and also correspondingly doing all the deallocation of the memory within the destructor.
Reply With Quote
  #3  
Old 27-01-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
C++ : Resource Acquisition is Initialization

Resource Acquisition Is Initialization is known as by the short form RAII. Resource Acquisition Is Initialization is a most popular design pattern in various object oriented programming languages such as C, D and Ada. Hence, during exception handling the destructors of all of the classes whose constructors can be successfully invoked are called. So, all of the the local objects that are previously allocated are automatically deallocated without calling explicitly to their destructors.
Reply With Quote
  #4  
Old 27-01-2010
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,502
Program : Resource Acquisition is Initialization

According to my knowledge about the C++ language the following example of code of lines explains you the Resource Acquisition is Initialization technique :
class A
{
int *s; public : A()
{cout<<" A is created ";
s=new int[10];
}
~A()
{cout<<" A is destroyed ";
delete [] s;
}
};
class B
{ public: B()
{
A a;
throw 44;
}
~B()
{
cout<<" B is destroyed ";
}
};
Reply With Quote
  #5  
Old 27-01-2010
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,832
Resource Acquisition Is Initialization

Hi, I think this explanation of the above program helps you to understand the Resource Acquisition Is Initialization more easily. Now, Hence B throws an exception right in its constructor therefore destructor of it won't be get called because the constructor was not invoked successfully. But the destructor of the class A would be definitely called and therefore the array ' s ' would be deallocated. So, we didn't have to take care of about the resource deallocation at the time when the exceptions can raised.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "C++ : Resource Acquisition is Initialization"
Thread Thread Starter Forum Replies Last Post
Intel has got the Acquisition For McAfee Aniela Networking & Security 4 02-03-2011 04:53 AM
Cluster error 1230: Cluster resource '%1' (resource type '%2', DLL '%3') either crashed or deadlocked. The EClipse Operating Systems 4 21-08-2010 05:03 AM
How Best to Handle an Acquisition? waynen Active Directory 2 22-05-2009 03:30 AM
How to calculate cost based on resource rate? I have more than 5 rates per resource boxta Microsoft Project 13 14-04-2009 04:43 PM
WMP 11 DRM license acquisition problem Murray206 Media Player 9 17-07-2006 09:42 AM


All times are GMT +5.5. The time now is 05:27 AM.