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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 4801CD176 for ; Tue, 26 Jul 2005 03:10:51 +0200 (CEST) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j6Q1AoFl006725 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Tue, 26 Jul 2005 03:10:51 +0200 Received: from [80.229.56.224] (helo=chetara) by ptb-relay03.plus.net with esmtp (Exim) id 1DxDy4-000433-0d for caml-list@yquem.inria.fr; Tue, 26 Jul 2005 02:10:48 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] How to do this properly with OCaml? Date: Tue, 26 Jul 2005 02:05:45 +0100 User-Agent: KMail/1.7.2 References: <200507241623.13705.Stephane.Glondu@crans.org> <1122251570.9027.362.camel@localhost.localdomain> In-Reply-To: <1122251570.9027.362.camel@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200507260205.45941.jon@ffconsultancy.com> X-Miltered: at concorde with ID 42E58D9A.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 initialise:01 initialise:01 arrays:01 mutable:01 damien:01 run-time:01 arrays:01 run-time:01 stl:01 tweaking:01 ocaml:01 hashtbl:01 trivial:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Monday 25 July 2005 01:32, skaller wrote: > On Sun, 2005-07-24 at 16:23 -0700, Stephane Glondu wrote: > > On Sunday 24 July 2005 14:55, skaller wrote: > > > If you have to initialise the store, it is expensive, > > > > I understand your point now. However, if you want your array to hold > > allocated values, you will always have to initialise the array. > > Not if the collector is modified by INRIA to support variable > length arrays: this is some kind of tagged block with > a mutable length count which limits how far along the block > the collector looks for boxes: the length count is less > than or equal to the actual number of allocated slots. As I recall, the last time we discussed this, Damien said that altering the run-time to allow variable-length arrays would slow the run-time down for all other code and would be likely to introduce bugs. I came from a C++/STL background and was accustomed to using extensible arrays. Having tweaking my perception of suitable data structures to be more appropriate when coding in OCaml, I now prefer the idea of a faster run-time and no extensible arrays. I've never actually needed them (except inside Hashtbl). > > Moreover, > > I think the overhead of this initialisation is insignificant compared to > > the GC overhead. > > I am not so sure: to initialise an array causes a store > in each slot, which forces the whole array to scroll > through your cache: if the array is big this means > disk paging/swapping activity. You could RLE the uninitialised elements to recover memmap capability. > ... > However that turned what in C is a trivial set of > library functions into a complex unreliable mess > and left me wondering whether the encoding was > properly transparent. I'd just go for the simplest approach, at least to start with. > > I didn't mean to change the dummy value all the time! Just take the first > > value as the dummy value, and keep it even if the first entry in the > > array changes. This will work fine for small values. > > But if you do that you have a reference to an object > that the client does not know about. So the client > will be confused if the object isn't finalised, > and that in turn could cause many other objects > to remain alive unexpectedly. How can that be a problem given that you (basically) cannot guarantee collection anyway? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. Technical Presentation Software http://www.ffconsultancy.com/products/presenta