From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA25218; Sat, 28 Sep 2002 00:27:16 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA25214 for ; Sat, 28 Sep 2002 00:27:15 +0200 (MET DST) Received: from comtv.ru (comtv.ru [217.10.32.4]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g8RMRDD02288; Sat, 28 Sep 2002 00:27:14 +0200 (MET DST) Received: from [10.0.66.9] ([10.0.66.9] verified) by comtv.ru (CommuniGate Pro SMTP 3.5.9) with ESMTP-TLS id 4675691; Sat, 28 Sep 2002 02:27:14 +0400 Date: Sat, 28 Sep 2002 02:27:29 +0400 (MSD) From: malc X-X-Sender: malc@home.oyster.ru To: Maxence Guesdon cc: Florian Hars , , Subject: Re: [Caml-list] (Sorry for my last post) lazyness, exceptions?, ocaml syntax rule-of-thumbs In-Reply-To: <20020927170755.142d6390.maxence.guesdon@inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 27 Sep 2002, Maxence Guesdon wrote: > If you want to read a whole file as a string, you can use the following function: > > let input_file_as_string file = > let chanin = open_in_bin file in > let len = 1024 in > let s = String.create len in > let buf = Buffer.create len in > let rec iter () = > try > let n = input chanin s 0 len in > if n = 0 then > () > else > ( > Buffer.add_substring buf s 0 n; > iter () > ) > with > End_of_file -> () > in > iter (); > close_in chanin; > Buffer.contents buf > I might be way off here, but shouldnt it be: let input_file_as_string file = let chanin = open_in_bin file in let len = in_channel_length chanin in let s = String.create len in really_input chanin s 0 (pred len); close_in chanin; s Even if your variant ran faster(and it doesnt), it suffers from Buffers resizing policy, meaning it will bail out sooner than String's maximal capacity is reached. -- mailto:malc@pulsesoft.com ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners