Version française
Home     About     Download     Resources     Contact us    
Browse thread
Ask for a more efficient way to deallocate memory (full version)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Ask for a more efficient way to deallocate memory (full version)
Zitat von Jon Harrop <jon@ffconsultancy.com>:

> On Sunday 09 December 2007 21:39, Fabrice.Pardo@lpn.cnrs.fr wrote:
> > Hello, and sorry for my previous unfinished message.
> >
> > As the function Unix.opendir returns a value,
> > we can expect that Unix.closedir will be automatically
> > called when the dir_handle value is no more referenced.
>
> You cannot expect that.
>
> > ...
> > My question is how to write a code as efficient
> > as it would be possible using a reference-counted language.
>
> RAII wrapped in a higher-order function as Olivier described is the
> idiomatic
> solution in OCaml.

1st: it has a little bug ;-)
2nd: why using a higher-level function here?

I would directly code the reading of the dir,
because the typical application of opendir would
be to read the contents of the dir.

But possibly you have some more ideas on how to use
the contents of a dir, different than reading ot's contents? ;-)

Or perhaps it's a matter of taste, what one preferes.

Higher-order functions are a fine thing;
I would use them, if necessary, but not
obessively every time and everywhere.

Ciao,
   Oliver

P.S.: One possibly also could use CPS for that open-read-close stuff.
      But I'm not sure if this would make sense.