Resource Acquisition Is Initialization (RAII) is a programming idiom used in several object-oriented languages like C++, D and Ada. The technique was invented by Bjarne Stroustrup to deal with resource allocation and deallocation in C++. In this language, the only code that can be guaranteed to be executed after an exception is thrown are the destructors of objects residing on the stack. Resource management therefore needs to be tied to the lifespan of suitable objects in order to gain automatic allocation and reclamation. They are acquired during initialization, when there is no chance of them being used before they are available, and released with the destruction of the same objects, which is guaranteed to take place even in case of errors.
RAII is vital in writing exception-safe C++ code: to release resources before permitting exceptions to propagate (in order to avoid resource leaks) one can write appropriate destructors once rather than dispersing and duplicating cleanup logic between exception handling blocks that may or may not be executed.
Read more about Resource Acquisition Is Initialization: Typical Uses, C++ Example
Famous quotes containing the words resource and/or acquisition:
“Your kind doesnt just kill men. You murder their spirits, you strangle their last breath of hope and freedom, so that you, the chosen few, can rule your slaves in ease and luxury. Youre a sadist just like the others, Heiser, with no resource but violence and no feeling but fear, the kind youre feeling now. Youre drowning, Heiser, drowning in the ocean of blood around this barren little island you call the New Order.”
—Curtis Siodmak (19021988)
“Always and everywhere children take an active role in the construction and acquisition of learning and understanding. To learn is a satisfying experience, but also, as the psychologist Nelson Goodman tells us, to understand is to experience desire, drama, and conquest.”
—Carolyn Edwards (20th century)