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=1.0 required=5.0 tests=AWL,DNS_FROM_RFC_BOGUSMX autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 50560BC6C for ; Fri, 18 Jan 2008 02:40:05 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq4HACqSj0fQOfEbWmdsb2JhbACBV4c+hngBIJ02 X-IronPort-AV: E=Sophos;i="4.25,213,1199660400"; d="scan'208";a="6260085" Received: from lgb-static-208.57.241.27.mpowercom.net (HELO sanddune.1969web.com) ([208.57.241.27]) by mail2-smtp-roc.national.inria.fr with ESMTP; 18 Jan 2008 02:40:04 +0100 Received: from [10.3.2.21] (zilles.1969web.com [10.3.2.21]) by sanddune.1969web.com (Postfix) with ESMTP id 98800BAD58D; Thu, 17 Jan 2008 17:39:59 -0800 (PST) Message-ID: <4790036E.3000203@1969web.com> Date: Thu, 17 Jan 2008 17:39:58 -0800 From: Karl Zilles User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: Christopher Kauffman Cc: OCaml Subject: Re: [Caml-list] Trouble with Scanf and files References: <478FF82D.1070305@cs.umn.edu> In-Reply-To: <478FF82D.1070305@cs.umn.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; scanf:01 scanf:01 ocaml:01 allocates:01 buffer:01 ocaml:01 garbage:01 garbage:01 wrote:01 caml-list:01 handles:03 let:03 let:03 perhaps:05 problem:05 Christopher Kauffman wrote: > I have encountered some difficulty using Scanf with a large number of > files. As suggested in the the Ocaml manual, my strategy so far when > reading a number of files has been to use Scanf.Scanning.from_file to > create a scanbuf for each file. I had always wondered if this would > cause problems with large numbers of files because I could not figure > out a way to close a file after completing operations on it. Today I > attempted to process too many and received a fatal system error. If one > allocates a scanbuf via > > let b = Scanf.Scanning.from_file "somefile" in ... > > is there a way to subsequently close the file when the buffer is no > longer needed? Or is this an issue that should be taken care of by the > garbage collector in some strange way? The documentation doesn't seem to be very clear. But, it would be unusual for Ocaml code to rely on the garbage collector to close file handles. Perhaps this is obvious, but maybe let ic = open_in "somefile" in let b = Scanf.Scanning.from_channel ic in ... close_in ic would solve your problem.