From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 38069BC57 for ; Thu, 18 Mar 2010 03:53:21 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhcCALEyoUvZSMDdkGdsb2JhbACbJhUBAQEBCQkMBxMDH7gyhHYE X-IronPort-AV: E=Sophos;i="4.51,262,1267398000"; d="scan'208";a="59270389" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail4-smtp-sop.national.inria.fr with ESMTP; 18 Mar 2010 03:53:21 +0100 Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate01.web.de (Postfix) with ESMTP id 5B86D14E616D5; Thu, 18 Mar 2010 03:53:12 +0100 (CET) Received: from [78.43.204.177] (helo=frosties.localdomain) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #4) id 1Ns5rE-0006qf-00; Thu, 18 Mar 2010 03:53:12 +0100 Received: from mrvn by frosties.localdomain with local (Exim 4.71) (envelope-from ) id 1Ns5rD-0002mX-Ii; Thu, 18 Mar 2010 03:53:11 +0100 From: Goswin von Brederlow To: Stas Miasnikou Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Buffer.add_channel hangs References: <36ae71be1003171327h3dfe72f5t74d43ebc88035e3d@mail.gmail.com> Date: Thu, 18 Mar 2010 03:53:11 +0100 In-Reply-To: <36ae71be1003171327h3dfe72f5t74d43ebc88035e3d@mail.gmail.com> (Stas Miasnikou's message of "Wed, 17 Mar 2010 22:27:14 +0200") Message-ID: <87bpem733c.fsf@frosties.localdomain> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1+UBipHoUJHnzVOdTpH25BeDoup2eOz4lWSlOp5 /BYOfX33AxyRD0Q26qjSugu9psIi2s+/Y7BYUV3m6IDbxLouaV w4XtZluJU= X-Spam: no; 0.00; buffer:01 ocaml:01 buffer:01 bigarray:01 mfg:98 char:01 caml-list:01 int:01 int:01 writes:01 bin:01 bin:01 hangs:01 hangs:01 unsigned:02 Stas Miasnikou writes: > Hi, > > OCaml 3.11.1, OpenBSD 4.6, i386. > > I am trying to read whole file by doing: > > let read_file_bin name = > let ic = open_in_bin name in > let b = Buffer.create 1024 in > (try Buffer.add_channel b ic max_int with _ -> ()); (* <-- HERE *) > close_in ic; > Array.init (Buffer.length b) (fun i -> int_of_char (Buffer.nth b i)) > > but it hangs on the line marked. Am I doing something wrong? > > Stas For the problem see the other mail. For a better solution I suggest you look at the Bigarray module. You can mmap your file as int8_unsigned array and have your read_file function done all in simple step. MfG Goswin