From: "Olivier Andrieu" <oandrieu@nerim.net>
To: "Christopher Kauffman" <kauffman@cs.umn.edu>
Cc: OCaml <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Trouble with Scanf and files
Date: Fri, 18 Jan 2008 09:30:02 +0100 [thread overview]
Message-ID: <95513600801180030j580fc54bmd83fdf993063a47d@mail.gmail.com> (raw)
In-Reply-To: <478FF82D.1070305@cs.umn.edu>
Hi,
On Jan 18, 2008 1:51 AM, Christopher Kauffman <kauffman@cs.umn.edu> 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 garbage collector does not close I/O channels.
Have a look at the implementation of Scanf:
http://camlcvs.inria.fr/cgi-bin/cvsweb/ocaml/stdlib/scanf.ml?rev=1.77
Apparently close_in is called when the end of file is encountered.
So if you stop scanning before the end of file, you'd better use
Scanning.from_channel and close the channel yourself.
--
Olivier
next prev parent reply other threads:[~2008-01-18 8:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-18 0:51 Christopher Kauffman
2008-01-18 1:39 ` [Caml-list] " Karl Zilles
2008-01-18 8:30 ` Olivier Andrieu [this message]
2008-01-18 23:12 ` Chris Kauffman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=95513600801180030j580fc54bmd83fdf993063a47d@mail.gmail.com \
--to=oandrieu@nerim.net \
--cc=caml-list@yquem.inria.fr \
--cc=kauffman@cs.umn.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).