caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: Yotam Barnoy <yotambarnoy@gmail.com>
Cc: Jon Harrop <jon@ffconsultancy.com>,
	Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] How much optimized is the 'a option type ?
Date: Sat, 1 Feb 2014 16:58:17 +0100	[thread overview]
Message-ID: <20140201155817.GF1783@frosties> (raw)
In-Reply-To: <CAN6ygOmzQzkd28xGywc5pM0wNfAaHCR6o6vC6KqEZXULKGT_MA@mail.gmail.com>

On Thu, Jan 30, 2014 at 01:43:59PM -0500, Yotam Barnoy wrote:
> BTW there's a compromise with unboxing that also has benefits, which is
> embedding. An [@embed] annotation could turn an array into an embedding
> array, for example. This would mean that an array would have boxed members
> within it ie. not accessible via pointers. The advantages are better cache
> performance and that the GC could be instructed when the array is
> completely flat ie. an embedded array without any pointers could be skipped
> by the GC in the mark phase. It would have full polymorphism capability.
> 
> The down side is that deallocating the array without deallocating the
> embedded structure would be tricky. When deallocating, you have to check
> every member to see if it should be deallocated as well. If not, you copy
> the member (minor heap) or reallocate the member where it is in memory
> (major heap).
> 
> Yotam

When deallocating the array you simply deallocate it all. You can't
have any pointers to inside the array floating around or the GC would
blow up. An array of embedded values can only be freed when nothing
has access to it any more at all. And access to members can only b
done as pointer to array + offset.

> On Wed, Jan 29, 2014 at 11:11 AM, Yotam Barnoy <yotambarnoy@gmail.com>wrote:
> 
> >
> > On Wed, Jan 29, 2014 at 3:32 AM, Jon Harrop <jon@ffconsultancy.com> wrote:
> >
> >> Yotam wrote:
> >> > Of course, once you unbox, all parametric polymorphism is lost
> >>
> >> Is it?
> >>
> >>
> > It is in haskell. In general, I don't think you can do any parametric
> > polymorphism without metadata.
> >
> >
> >> You would have to box the tuple before passing it to a polymorphic
> >> function
> >> with the type 'a -> 'a. However, if the function has the type 'a * 'b ->
> >> 'b
> >> * 'a then you could always unbox, right?

let f =
  let t = ref 0 in
  function (x, y) ->
    t := y;
    (y, x)

With f being unboxed you end up with a pointer to the middle of a
tuple in t and the GC goes *BOOM*.

Unboxed values allow only some operations.

> > I don't think so. Without metadata, how do you know where one tuple member
> > ends and another begins?
> >
> > Yotam

Being unboxed you get the first member in R0 and the second in R1.

MfG
	Goswin

  reply	other threads:[~2014-02-01 15:58 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-17  7:35 Damien Guichard
2014-01-17  7:55 ` David House
2014-01-17  8:16   ` Julien Blond
2014-01-17  8:40     ` David House
2014-01-17  9:10       ` Gabriel Scherer
2014-01-17  9:22         ` Simon Cruanes
2014-01-17 17:57           ` Gerd Stolpmann
2014-01-18  1:35             ` Jon Harrop
2014-01-19  6:19               ` oleg
2014-01-21  1:51                 ` Francois Berenger
2014-01-18  1:01         ` Jon Harrop
2014-01-24 10:06         ` Alain Frisch
2014-01-24 10:16           ` Alain Frisch
2014-01-24 13:32             ` Yaron Minsky
     [not found]       ` <CAK=fH+jfi=GsMYBZzmuo=V5UAWimyxiiamY2+DkLg6F0i8XHGw@mail.gmail.com>
2014-01-17  9:11         ` David House
2014-01-17 11:23           ` Jonathan Kimmitt
2014-01-17 13:46             ` Nicolas Braud-Santoni
2014-01-17 13:56               ` Frédéric Bour
2014-01-17 14:02               ` Yaron Minsky
2014-01-17 14:09                 ` Simon Cruanes
2014-01-17 22:52                   ` Yaron Minsky
2014-01-18  1:37                   ` Jon Harrop
2014-01-17 14:24                 ` Gabriel Scherer
2014-01-17 22:29                   ` Yaron Minsky
2014-01-18  1:27                 ` Jon Harrop
2014-01-18  1:18             ` Jon Harrop
2014-01-20 10:16             ` Goswin von Brederlow
2014-01-20 11:23               ` Jonathan Kimmitt
2014-01-21  2:05                 ` Francois Berenger
2014-01-22 21:22                   ` Jon Harrop
2014-01-22 21:26               ` Jon Harrop
2014-01-23  9:29                 ` Goswin von Brederlow
2014-01-23 23:20                   ` Jon Harrop
2014-01-23 23:28                     ` Yotam Barnoy
2014-01-24  8:22                       ` Jon Harrop
2014-01-24  8:34                         ` Andreas Rossberg
2014-01-24 16:56                           ` Jon Harrop
2014-01-27 15:29                             ` Goswin von Brederlow
2014-01-27 16:18                               ` Yotam Barnoy
2014-01-29  7:56                                 ` Goswin von Brederlow
2014-01-29  8:32                                 ` Jon Harrop
2014-01-29 16:11                                   ` Yotam Barnoy
2014-01-30 18:43                                     ` Yotam Barnoy
2014-02-01 15:58                                       ` Goswin von Brederlow [this message]
2014-01-30 21:31                                     ` Jon Harrop
2014-01-30 21:43                                       ` Yotam Barnoy
2014-01-31  8:26                                         ` Jon Harrop
2014-02-01 15:40                                 ` Goswin von Brederlow
2014-01-27 10:03                         ` Goswin von Brederlow
2014-01-17 14:36 ` Markus Mottl
2014-01-17 15:49   ` Yotam Barnoy
2014-01-17 16:22     ` Markus Mottl
2014-01-20 10:09   ` Goswin von Brederlow

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=20140201155817.GF1783@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    --cc=jon@ffconsultancy.com \
    --cc=yotambarnoy@gmail.com \
    /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).