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: Marcin 'Qrczak' Kowalczyk <qrczak@k...>
Subject: Re: [Caml-list] Re: exception safety / RAII ?
Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Having a GC gives you a freedom when designing an API that is completely
> incomparable to the minor convenience of not having to explicitly
> close files.  Compare the success of C++ destructors to deal with
> file-closing and the insufficiency of those same destructors to deal with
> object deallocation (leading to the never ending use of reference counting
> and/or explicit copying).

The fact that GC is useful for freeing memory doesn't imply that we
should have no convenient way for closing files.

IMHO there should be something similar to C# 'using', especially given
that the GC will not close dropped files.

The current semantics of C# 'using' is not enough in the presence
of asynchronous exceptions. If OCaml wants to ever have reliable
asynchronous exceptions, its 'using' should have three distinguished
parts: acquire the resource, use it, and release it.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/