Question

I recently learned about the wonderful memory management technique of RAII, which seems so much cleaner than the new/delete headache I learned in school years ago (I haven't looked at much C++ during the intervening years).

I'm trying to track down when this great technique was added to C++. Was it always there and I just missed the memo? What's the oldest version of the C++ standard which supports RAII?

[UPDATE: OK I realize now why this isn't an ideal SO question -- I have no practical way to verify whether any given answer is correct! Nonetheless I'm still very interested to learn the answer, and I assume the majority opinion will be true.

What I'm hearing is that it's always been there, which I don't doubt is true, but begs the question how come none of my old text books mention it? I just checked Meyers' Effective C++ 2nd edition which I have handy, and will check older texts tonight. Maybe the term was only recently coined, while the technique existed long before?]

Was it helpful?

Solution

When exactly the term "RAII" was coined, I'm not sure. But the technique itself existed in C++ from the moment of its invention, circa 1979.

The first version of the C++ ISO standard was published in 1998.

OTHER TIPS

Any language that has scoped variables with automatic destructor calls is able to do RAII. C++ had this concept from the very beginning as calling destructor when execution leaves scope where variable is declared was in C++ from the very beginning.

Wikipedia's claim that Stroustrup invented RAII is backed by a reference to his book Design and Evolution of C++, published in 1994.

I don't have a copy to check, but it would seem to date from at least this time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top