From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5EAA27EC6E for ; Fri, 17 Jan 2014 09:16:36 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of julien.blond@gmail.com) identity=pra; client-ip=209.85.219.53; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="julien.blond@gmail.com"; x-sender="julien.blond@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of julien.blond@gmail.com designates 209.85.219.53 as permitted sender) identity=mailfrom; client-ip=209.85.219.53; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="julien.blond@gmail.com"; x-sender="julien.blond@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-oa0-f53.google.com) identity=helo; client-ip=209.85.219.53; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="julien.blond@gmail.com"; x-sender="postmaster@mail-oa0-f53.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AssDAJFf2FLRVds1lGdsb2JhbABZg0NWqCiKFIhVgQcIFg4BAQEBBwsLCRIqgiUBAQEDAUABGxILAQMBCwYFBAcDCg0hIgERAQUBChIGExKHXQEDCQgNnQ6MXIMJkhQKGScDCmSEchEBBQyObwQHhDgEmCGBMY55GCmEWjs X-IPAS-Result: AssDAJFf2FLRVds1lGdsb2JhbABZg0NWqCiKFIhVgQcIFg4BAQEBBwsLCRIqgiUBAQEDAUABGxILAQMBCwYFBAcDCg0hIgERAQUBChIGExKHXQEDCQgNnQ6MXIMJkhQKGScDCmSEchEBBQyObwQHhDgEmCGBMY55GCmEWjs X-IronPort-AV: E=Sophos;i="4.95,670,1384297200"; d="scan'208";a="45129100" Received: from mail-oa0-f53.google.com ([209.85.219.53]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Jan 2014 09:16:35 +0100 Received: by mail-oa0-f53.google.com with SMTP id m1so2928345oag.26 for ; Fri, 17 Jan 2014 00:16:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=6oCLNaP2I20/cQQym0UI455x2nzX6/ci22bfbQfdlYI=; b=sPwFrXcUwLS10LgckRIwb2Hz2oqObhMGnzY+Dtbe8zt8n3roj0nq/dmkpAZV7cviSa VtMkKVN330YujvU4V9EYLuP+Oj1su9MTbptQDdGEKm4cTG+J915QnacHfru4MY0s4edo ZhlGHBWYd2mAexEB2cJnDEdLUMzoFaslHmbi06h7z84FnBpisLdn0T2RFwcKnDaui0C+ RnoXD6jXII0KjGjt6QpWsAH/yPxNgQb8af4cDUkU0FC9CowqiD5vglryVn4eaE9VWYrv 51V9wqEVKiKWXW3RvzjJoNiwtABT/+M6XTqJr89QAxt/54HGX1MAUA6WuaE1usmB4uvv w/ug== MIME-Version: 1.0 X-Received: by 10.60.220.199 with SMTP id py7mr490692oec.26.1389946593903; Fri, 17 Jan 2014 00:16:33 -0800 (PST) Received: by 10.60.60.10 with HTTP; Fri, 17 Jan 2014 00:16:33 -0800 (PST) In-Reply-To: References: <523666417617602473@orange.fr> Date: Fri, 17 Jan 2014 09:16:33 +0100 Message-ID: From: Julien Blond To: David House Cc: Damien Guichard , Caml Mailing List Content-Type: multipart/alternative; boundary=001a113671a8fc8b0c04f02628f2 Subject: Re: [Caml-list] How much optimized is the 'a option type ? --001a113671a8fc8b0c04f02628f2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable > An option value always takes two words: one for the header, and then either a pointer or a word that means "None". No. From the reference manual =A7 19.3.4 : type 'a option =3D None (* Val_int(0), i.e. just an integer value= =3D 1 word *) | Some of 'a (* block of size 1 =3D [(header =3D 1 w= ord) + (1 field =3D 1 word)] =3D 2 words *) 2014/1/17 David House > It behaves identically to that type. > > It is just like any other sum type. However, due to the way that sum types > are represented in memory, it is not that inefficient. The only thing that > makes it less efficient than a C pointer is the header block (necessary f= or > the GC). An option value always takes two words: one for the header, and > then either a pointer or a word that means "None". > > > On 17 January 2014 07:35, Damien Guichard wrote: > >> Hello, >> >> Compared to the code : >> >> type 'a option =3D None | Some of 'a >> >> How do an 'a option value performs ? >> Any allocation saved ? >> Any indirection removed ? >> >> Is 'a option just like any sum type ? >> Or is 'a option more like an ANSI C pointer type ? >> >> Regards, >> >> Damien Guichard >> >> >> >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa.inria.fr/sympa/arc/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs >> > > --001a113671a8fc8b0c04f02628f2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
> An option value always takes two = words: one for the header, and then either a pointer or a word that means &= quot;None".

No. From the reference manual =A7 19.3.4 :

type 'a option =3D None=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (* Val_= int(0), i.e. just an integer value =3D 1 word *)
=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 | Some of 'a=A0=A0 = (* block of size 1 =3D [(header =3D 1 word) + (1 field =3D 1 word)] =3D 2 w= ords *)


2014/1/= 17 David House <dhouse@janestreet.com>
It behaves identically to that type.

It= is just like any other sum type. However, due to the way that sum types ar= e represented in memory, it is not that inefficient. The only thing that ma= kes it less efficient than a C pointer is the header block (necessary for t= he GC). An option value always takes two words: one for the header, and the= n either a pointer or a word that means "None".

On 17 January 2014 07:35, Damien Guichard = <alphablock@orange.fr> wrote:
Hello,

Compared to the code :

type 'a option =3D None | Some of 'a

How do an 'a option value performs ?
Any allocation saved ?
Any indirection removed ?

Is 'a option just like any sum type ?
Or is 'a option more like an ANSI C pointer type ?

Regards,

Damien Guichard



--
Caml-list mailing list. =A0Subscription management and archives:
ht= tps://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--001a113671a8fc8b0c04f02628f2--