Content deleted Content added
m stub |
Poldi~enwiki (talk | contribs) No edit summary |
||
Line 1:
[[de:Ressourcenbelegung ist Initialisierung]]
'''Resource Acquisition Is Initialization''' (often referred to by the acronym '''RAII''') is a popular programming technique in [[
The acquisition is bound to the construction (initialization) whereas the release is bound to the destruction (uninitialization) of the variable. Since a destructor of an automatic variable is called when leaving its scope, it can be guaranteed that the resource is released as soon as the variable's life time ends. This is also true for cases when an exception occurs. Thus, RAII is a key concept for writing exception aware code.
Furthermore the ownership of dynamically allocated memory (with <tt>new</tt>) can be controlled with RAII technique. For this purpose, the C++ Standard Library defines <tt>auto_ptr</tt>.
▲A stereotypical example of RAII is the [[Standard Template Library]]'s file-[[stream]] [[class]]. An input file stream is opened in the object's constructor, and it is closed upon destruction of the object. Since C++ allows objects to be allocated on the [[Stack (computing)|stack]], C++'s scoping mechanism can be used to control file access.
==External links==
|