caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Stephane Glondu <Stephane.Glondu@crans.org>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] How to do this properly with OCaml?
Date: Mon, 25 Jul 2005 10:32:50 +1000	[thread overview]
Message-ID: <1122251570.9027.362.camel@localhost.localdomain> (raw)
In-Reply-To: <200507241623.13705.Stephane.Glondu@crans.org>

[-- Attachment #1: Type: text/plain, Size: 4464 bytes --]

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.

> 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.

Why do all that when the values will never be read?
We do not even know in advance how much of the
array will actually be used. Consider an array
of length 10,000 elements, where only 100 are used.
We allocate space for 10,000 because we're conservative
and want the program to run on many sized data sets.

BTW: this is a *real* issue an Ocaml user had.

Ok, so my argument is flawed as follows: the whole
point of a variable length array is to keep the size
of the array roughly the size of the data it actually
holds: when extending, we're already initialising
the new array with data from the old one, and the
overhead initialising the rest is only going
to double the time taken.. unless you happen
to hit a cache size boundary, when it could
take 10-100 times longer than necessary.

So -- you could indeed be correct, but it isn't
entirely clear that gratuitous writes are not
going to impact performance.


> > and if you have to provide a dummy value it is hard
> > to use.
> 
> Maybe hard is not the appropriate word. I would just say annoying. You can 
> always define easily a dummy value when you define a (non-empty) type.

Think of a class type, whose constructor function itself 
takes other class values as arguments .. it can be quite 
complicated to set up such values, and, worse, 
Ocaml being imperative doing so may have side-effects.

This isn't far fetched at all -- it happened to me :)

That is why I implemented a variable length array,
to get around this obstacle. I used the 'one element
is taken as a dummy value' technique (no Obj.magic!).

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 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. Even if there are
no side-effects on finalisation, the extra memory
use could be a problem.

> If you are planning to put 
> huge values in the array,

Not just huge values: values that contain references
to other values .. such as in a graph .. occupy
a lot of memory. Much of that data structure may be
shared, but we normally expect unreferenced parts
of the graph to die, and release memory.

> > That won't happen in Buffer because you can't modify it,
> > but it must be allowed in more general variable length
> > mutable array.
> 
> What do you mean?

The current implementation makes buffers extensible
but immutable. However, for a general variable length
array you would like to not only modify elements,
but insert and delete as well.

Without this additional requirement, using the
'first' element as a dummy value would work fine:
that is, you are correct 'a array option idea
for Buffer would be make efficient elimination
of the 'dummy value' requirement possible (although
not eliminating the need to initialise the array).

But for a true variable length array, and without
gratuitously hanging on to an unused value,
you'd need each store to the first element to
also store in every unused slot.

-- 
John Skaller <skaller at users dot sourceforge dot net>


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2005-07-25  0:32 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-22 14:26 Thomas Fischbacher
2005-07-22 14:52 ` [Caml-list] " Eric Cooper
2005-07-22 15:26 ` [SPAM_PROBABLE] - [Caml-list] How to do this properly with OCaml? - Bayesian Filter detected spam Christophe Dehlinger
2005-07-22 18:58   ` [Caml-list] How to do this properly with OCaml? Stephane Glondu
2005-07-22 15:50 ` Berke Durak
2005-07-22 16:47   ` brogoff
2005-07-22 15:54 ` Michel Quercia
2005-07-23  5:00 ` Michael Alexander Hamburg
2005-07-23 12:34   ` Xavier Leroy
2005-07-23 13:16     ` Berke Durak
2005-07-23 16:36       ` Stephane Glondu
2005-07-23 18:27         ` Berke Durak
2005-07-23 18:50           ` Matthieu Sozeau
2005-07-24  8:35             ` Berke Durak
2005-07-23 19:18           ` Stephane Glondu
2005-07-23 19:35             ` Thomas Fischbacher
2005-07-23 19:50               ` Stephane Glondu
2005-07-23 19:59                 ` Thomas Fischbacher
2005-07-23 20:15                   ` Brian Hurt
2005-07-23 23:16                     ` james woodyatt
2005-07-23 23:27                   ` Stephane Glondu
2005-07-23 18:37     ` Michael Alexander Hamburg
2005-07-23 18:52       ` Bardur Arantsson
2005-07-23 21:35         ` [Caml-list] " Michael Alexander Hamburg
2005-07-23 19:19     ` [Caml-list] " Thomas Fischbacher
2005-07-24  7:27     ` [Caml-list] "Just say no!" campaign against Obj [was: How to do this properly with OCaml?] Alex Baretta
2005-07-24  8:02       ` [Caml-list] "Just say no!" campaign against Obj james woodyatt
2005-07-24 17:27       ` Stephane Glondu
2005-07-25  8:43         ` Alex Baretta
2005-07-24 21:37       ` [Caml-list] "Just say no!" campaign against Obj [was: How to do this properly with OCaml?] brogoff
2005-07-25  8:15         ` Alex Baretta
2005-07-25 17:08           ` brogoff
2005-07-25  8:57         ` Alex Baretta
2005-07-24 17:33     ` [Caml-list] How to do this properly with OCaml? skaller
2005-07-24 18:13       ` Stephane Glondu
2005-07-24 18:48         ` skaller
2005-07-24 19:14           ` Stephane Glondu
2005-07-24 20:29             ` skaller
2005-07-24 20:49               ` skaller
2005-07-24 21:08                 ` Stephane Glondu
2005-07-24 21:55                   ` skaller
2005-07-24 23:23                     ` Stephane Glondu
2005-07-25  0:32                       ` skaller [this message]
2005-07-25  6:45                         ` Stephane Glondu
2005-07-25 11:35                           ` skaller
2005-07-26  0:47                             ` Brian Hurt
2005-07-26  0:56                               ` Jere Sanisalo
2005-07-26  1:10                                 ` Brian Hurt
2005-07-26  1:34                                   ` Jere Sanisalo
2005-07-26  9:03                                     ` Richard Jones
2005-07-27 17:21                                     ` skaller
2005-07-27 19:44                                       ` [Caml-list] Games Jon Harrop
2005-07-27 20:35                                         ` Jere Sanisalo
2005-07-28  0:13                                           ` Jon Harrop
2005-07-28  1:12                                             ` Jere Sanisalo
2005-07-28  2:44                                               ` Jon Harrop
2005-07-28  4:49                                                 ` skaller
2005-07-28 19:48                                                   ` Jon Harrop
2005-07-28 21:32                                                     ` David Thomas
2005-07-28 22:31                                                       ` Jon Harrop
2005-07-29  1:44                                                         ` Michael Walter
2005-07-29  2:32                                                         ` David Thomas
2005-07-29  3:52                                                           ` skaller
2005-07-29 12:57                                                             ` David Thomas
2005-07-28 10:58                                               ` Gerd Stolpmann
2005-07-28 17:19                                         ` David Thomas
2005-07-28 19:22                                           ` Jon Harrop
2005-07-27 21:13                                       ` [Caml-list] How to do this properly with OCaml? Pal-Kristian Engstad
2005-07-27 22:28                                         ` skaller
2005-07-28  1:47                                           ` Michael Walter
2005-07-27 23:17                                         ` [Caml-list] Games Jon Harrop
2005-07-28  0:03                                         ` [Caml-list] How to do this properly with OCaml? Paul Snively
2005-07-28 18:26                                           ` Jonathan Bryant
2005-07-28 23:10                                             ` Paul Snively
2005-07-27 16:03                                   ` skaller
2005-07-26  1:01                               ` Stephane Glondu
2005-07-26  1:15                                 ` Brian Hurt
2005-07-27 15:33                                 ` skaller
2005-07-30 23:24                                   ` Thomas Fischbacher
2005-07-31  0:06                                     ` Jon Harrop
2005-07-31  3:10                                       ` skaller
2005-07-31  2:54                                     ` skaller
2005-07-26 20:32                               ` David Thomas
2005-07-27 15:05                               ` skaller
2005-07-27 15:29                                 ` Jon Harrop
2005-07-27 15:35                                   ` David Thomas
2005-07-27 20:11                                     ` skaller
2005-07-28 16:35                                       ` David Thomas
2005-07-30 23:33                                     ` Thomas Fischbacher
2005-07-31  0:39                                       ` james woodyatt
2005-07-27 19:59                                   ` skaller
2005-07-26  1:22                             ` Jon Harrop
2005-07-27 17:23                               ` skaller
2005-07-26  1:05                         ` Jon Harrop
2005-07-26  1:20                           ` Brian Hurt
2005-07-26  1:28                             ` Jon Harrop
2005-07-27 17:03                             ` skaller
2005-07-27 16:09                           ` skaller
2005-07-24 23:26               ` Brian Hurt
2005-07-25 17:21       ` Ken Rose
2005-07-25 19:19         ` skaller
2005-07-26  7:10           ` Alex Baretta
2005-07-23 18:58   ` Thomas Fischbacher
2005-07-26  1:32 Jon Harrop
     [not found] <200507271635.28931.jon@ffconsultancy.com>
2005-07-27 16:31 ` David Thomas

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=1122251570.9027.362.camel@localhost.localdomain \
    --to=skaller@users.sourceforge.net \
    --cc=Stephane.Glondu@crans.org \
    --cc=caml-list@yquem.inria.fr \
    /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).