From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=NO_REAL_NAME autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id C0739BC6B for ; Sun, 9 Dec 2007 22:39:48 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAAbvW0fBMKMDh2dsb2JhbACObnUCAQgKKQ X-IronPort-AV: E=Sophos;i="4.23,274,1194217200"; d="scan'208";a="20148154" Received: from zenobe.lpn.cnrs.fr ([193.48.163.3]) by mail4-smtp-sop.national.inria.fr with ESMTP; 09 Dec 2007 22:39:48 +0100 Received: from webmail.lpn.cnrs.fr (localhost.localdomain [127.0.0.1]) by zenobe.lpn.cnrs.fr (Postfix) with ESMTP id 31ED5524005 for ; Sun, 9 Dec 2007 22:39:48 +0100 (CET) Received: from 81.57.198.61 (SquirrelMail authenticated user fab) by webmail.lpn.cnrs.fr with HTTP; Sun, 9 Dec 2007 22:39:48 +0100 (CET) Message-ID: <39980.81.57.198.61.1197236388.squirrel@webmail.lpn.cnrs.fr> Date: Sun, 9 Dec 2007 22:39:48 +0100 (CET) Subject: Ask for a more efficient way to deallocate memory (full version) From: Fabrice.Pardo@lpn.cnrs.fr To: caml-list@yquem.inria.fr User-Agent: SquirrelMail/1.4.9a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Spam: no; 0.00; opendir:01 opendir:01 garbage:01 unix:01 unix:01 exception:01 referenced:02 deallocate:03 seems:03 let:03 let:03 finalise:04 raises:05 tmp:05 tmp:05 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.