Results 1 to 5 of 5

Thread: C++ : Resource Acquisition is Initialization

  1. #1
    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?

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    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.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    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.

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    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 ";
    }
    };

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    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.

Similar Threads

  1. Replies: 8
    Last Post: 08-05-2012, 12:46 PM
  2. Intel has got the Acquisition For McAfee
    By Aniela in forum Networking & Security
    Replies: 4
    Last Post: 02-03-2011, 04:53 AM
  3. Basic idea about MERGER and ACQUISITION
    By Cassius Marcellus in forum Off Topic Chat
    Replies: 4
    Last Post: 17-11-2010, 10:46 PM
  4. Replies: 4
    Last Post: 21-08-2010, 04:03 AM
  5. Media Usage Rights Acquisition
    By settler in forum Media Player
    Replies: 2
    Last Post: 28-05-2008, 01:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,036,673.19838 seconds with 16 queries