Version française
Home     About     Download     Resources     Contact us    
Browse thread
exception safety / RAII ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michael Walter <michael.walter@g...>
Subject: Re: [Caml-list] Re: exception safety / RAII ?
On Thu, 10 Mar 2005 16:52:01 +0000, Jon Harrop <jon@ffconsultancy.com> wrote:
> > Can you give examples where it's useful?  I don't consider "not needing to
> > call `close' on line NNNN of my code" to be useful.
> 
> OpenGL display lists from earlier in this thread.

Typically you manage your rendering resources at well-defined points
in the life time of a program (for performance reasons -- for
performance reasons you probably also wouldn't use display lists, but
that is besides the point), so I don't see how this is a problem

> > > In the case of files, yes.  More generally, this can be applied to all
> > > sorts of external resources where that is not true.
> >
> > Might be: there's no way we can generalize.  I'm talking about files here.
> > Finalizers are great, but they shouldn't be used for files.
> 
> Let me try another file-specific example then: Programs which save output at
> some point during their execution. From the users point of view, there is no
> "visible" difference between having the program close the file as soon as
> writing is complete and leaving it up to the GC to close the file a short
> time afterwards (and before it completes). I have many such programs.

You might want to be able to process the output file as soon as it's
written, not as soon as the GC decides to close the file. Also,
wouldn't it be trivial to just implement it "the nice way" (maybe I
think of different cases where "programs [..] save output")?

Michael