Re: What do you use RAII for?
On Mar 27, 3:11 am, dean <deanbrow...@yahoo.com> wrote:
What kinds of things have you used Resource Acquisition is
Initialization for? I've been using it in a few places and its
remarkably useful. Here is where I've use this currently:
1. Creating and/or maintaining hourglass cursors in and between
2. Oracle transaction handling and rolling back on exception.
3. Setting bind variable lifetimes in an SQL library.
4. Opening and closing files.
5. Opening and closing database cursors.
It depends on just how far you're willing to stretch it. I
frequently use something more or less similar for transaction
management; if the destructor is called before the commit
function has been called, it does a rollback. I guess the
presence of the commit function means that it isn't strictly
speaking RAII, but in practice, while I often need scoped clean
up, except for resources like locks, the clean-up in the case of
errors is almost always different from the normal case. If
you're outputting to a file, for example, you'll remove the file
if it hasn't been correctly closed (committed), or if there was
an error on the close.
James Kanze (GABI Software) email:email@example.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34