GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 27 of 203    Print  
Can you explain the term "resource acquisition is initialization?"

  
Total Answers and Comments: 2 Last Update: September 23, 2009     Asked by: suman 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 07, 2005 01:08:38   #1  
subbu4u Member Since: October 2005   Contribution: 1    

RE: Can you explain the term "resource acquisition is ...
Resource Acquisition is Initialisation or shortly RAII is a term closely connected with exception handling and automatic garbage collection(speaking loosely). RAII is defined as the technique of performing all necessary resource initialisation work right within the body of the constructor itself and correspondingly doing all the deallocation within the destructor. Since during exception handling destructors of all the classes whose constructors have been successfully invoked are called therefore all the local objects previously allocated are automatically deallocated without explicitly calling their destructors.the following example explains the RAII technique:class X{ int *r; public: X(){cout<< X is created ; r new int[10]; } ~X(){cout<< X is destroyed ; delete [] r; }};class Y{ public: Y(){ X x; throw 44; } ~Y(){cout<< Y is destroyed ;}};Now since Y throws an exception right in its constructor therefore its destructor won't get called becuse the constructor was not invoked successfully. But the destructor of the class X will definitely be called and therefore the array 'r' will be deallocated. So we didn't have to care about resource deallocation at the time exceptions are raised.
 
Is this answer useful? Yes | No
September 23, 2009 04:02:24   #2  
vidhudatta Member Since: September 2009   Contribution: 4    

RE: Can you explain the term "resource acquisition is initialization?"
It is the technique of performing all the necessary resource allocation in constructor only and all the cleanind in the destructor.
 
Is this answer useful? Yes | No

 Related Questions

"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms 
Latest Answer : C++ enables polymorphism - The ability of obejcts of different classes related by inheritance respond differntly to the same function call. ...

Latest Answer : It is the technique of performing all the necessary resource allocation in constructor only and all the cleanind in the destructor. ...
Read Answers (2) | Asked by : suman

Latest Answer : Virtual destructor makes sure that all derived objects are deleted first before deleting the base class objects. When base class pointer assigned with Derived class objects, the virtual destructor of the base class make sure that it deletes the derived ...
Read Answers (4) | Asked by : suji

Explain "passing by value", "passing by pointer" and "passing by reference"
Read Answers (2) | Asked by : suji
Tags : Pointer

Latest Answer : As long as no diamond problems (improper inheritance),  single or multiple inheritance can all be proper inheritance. When usng multiple inheritance with diamond problem, you can use virtual inheritance to make the multiple inheritance a proper one. ...
Read Answers (3) | Asked by : tanish

Latest Answer : Static variables of a class can only be initialized like this CLASS_NAME::STATIC_VAR_NAME = VAR_VALUE; ...

Latest Answer : Encpasulation is the process of packaging the classes into the public interfaces and private implementation, so that, any changes in the code will not effect the implmentation. The interfaces should be designed such that the actual implementation would ...
Read Answers (5) | Asked by : kaushal

What is the difference between char str, char *str and char* str ?Explain the meaning of char* or int* ?

what is inheritance? why we use it? plzz can anybody explain me with one example and where we use that concept? 
Latest Answer : The main use of inheritance is to provide reusability of codes .Through inheritance base class objects and functions are acquired by derived class so there is no need to specify it again in derived class ...

why we fallow top down approach in c-language and bottom up approach in c++?explain? 
Latest Answer : Top-down approach views from generalizaton to specilization where as bottom-up approach does the reverse of it. ...
Read Answers (2) | Asked by : suhana


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

Explain about TNSPING

You can also use tnsping utility on command prompt to check Oracle Net connectivity. Follow these steps to check the connection to particular SID. Open Command prompt. Write tnsping &lt; SID for the database connectivity you want to check &gt; If you get the message &ldquo;Used TNSNAMES
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

Short-term versus Long-term Job Experience

One big question in today&rsquo;s career world asks which resume is more beneficial, one that shows numerous types of jobs performed for the short term, or a few jobs in the same field where the employee remained for the long term? Most career professionals would state that the latter is more va
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.&nbsp; By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.&nbsp; IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape