Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Ask for a more efficient way to deallocate memory (full version)
@ 2007-12-09 21:39 Fabrice.Pardo
  2007-12-09 21:55 ` [Caml-list] " Olivier Andrieu
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Fabrice.Pardo @ 2007-12-09 21:39 UTC (permalink / raw)
  To: caml-list

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.
That's not the case, and calling opendir too many times as in

for i = 1 to 2000 do
  let d = Unix.opendir "/tmp" in ()
done;;

  raises
Exception: Unix.Unix_error (Unix.EMFILE, "opendir", "/tmp").

Replacing Unix.opendir by safe_opendir:

let safe_opendir path =
  let _ = Gc.major ()
  and d = Unix.opendir path
  in Gc.finalise Unix.closedir d

seems a solution, but the efficiency is very low due to high
cost of garbage collector calling function.

My question is how to write a code as efficient
as it would be possible using a reference-counted language.

Thanks.


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2007-12-16 15:57 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-09 21:39 Ask for a more efficient way to deallocate memory (full version) Fabrice.Pardo
2007-12-09 21:55 ` [Caml-list] " Olivier Andrieu
2007-12-10 11:25   ` Fabrice Pardo
2007-12-10 12:03     ` Michaël Le Barbier
2007-12-10 16:33     ` Oliver Bandel
2007-12-10 20:27       ` Richard Jones
2007-12-10 21:05         ` Oliver Bandel
2007-12-10 21:15         ` Gordon Henriksen
2007-12-10 22:13           ` Oliver Bandel
2007-12-10 22:59             ` Jon Harrop
2007-12-10 23:29               ` Jon Harrop
2007-12-11  2:03               ` Yitzhak Mandelbaum
2007-12-15 21:33               ` Oliver Bandel
2007-12-16 15:14                 ` Jon Harrop
2007-12-10 23:24           ` Jon Harrop
2007-12-09 21:57 ` Oliver Bandel
2007-12-09 22:12 ` Jon Harrop
2007-12-09 22:34   ` Oliver Bandel
2007-12-09 22:16 ` Oliver Bandel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox