Pregunta

Last time I see some video where Mr. Stroustrup talking about RAII in C++. I wanted to know more and found this page:

https://www.securecoding.cert.org/confluence/display/cplusplus/MEM44-CPP.+Do+not+leak+resources+when+handling+exceptions

Is this MEM44-CPP just a proposal to the next specification of C++ or is it already available? How do I know my compilation tools supports RAII?

¿Fue útil?

Solución 2

RAII is a design pattern, based on the fact that the destructor is called whenever the scope of an object is left, and this, regardless of the reason for leaving the scope. As design patterns go, it's use is limited to languages which have destructors which are called whenever the scope of an object is left: C++ and (I think) Ada 95, although there may be others.

As it is a design pattern, it has nothing to do with the compiler, except that it necessitates having destructors called at the right time. This has been a feature of the C++ language since the very earliest days, although early compilers often got it wrong. The last compiler I'm aware of which had problems in this respect, however, was the C++ in Visual Studios 2008 (which sometimes failed to call destructors it should have). Most other compilers have been fine since the mid 1990's.

Otros consejos

RAII (Resource Acquisition Is Initialization) is something inherent to C++, or rather something that can be used to alleviate memory handling issues when applied correctly, by you.

Every C++ compiler "supports" RAII.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top