Version française
Home     About     Download     Resources     Contact us    
Browse thread
Trouble with Scanf and files
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Karl Zilles <zilles@1...>
Subject: Re: [Caml-list] Trouble with Scanf and files
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.