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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 36E177EC6E for ; Fri, 17 Jan 2014 08:55:46 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of dhouse@janestreet.com) identity=pra; client-ip=38.105.200.229; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dhouse@janestreet.com"; x-sender="dhouse@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of dhouse@janestreet.com designates 38.105.200.229 as permitted sender) identity=mailfrom; client-ip=38.105.200.229; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dhouse@janestreet.com"; x-sender="dhouse@janestreet.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@tot-dmz-mxout1.janestreet.com) identity=helo; client-ip=38.105.200.229; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dhouse@janestreet.com"; x-sender="postmaster@tot-dmz-mxout1.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhMCAJFf2FImacjlnGdsb2JhbABZg0NWqCiKFIhVgQceDgEBAQEBBhYJPIIlAQEBAwFAAQEsCwEECwsEBwMXISISAQUBChIGExKHXgMJCAMCCJ0OixOEUgEFklgDhWARBo57BAeEOJglgTGOeRgphFk X-IPAS-Result: AhMCAJFf2FImacjlnGdsb2JhbABZg0NWqCiKFIhVgQceDgEBAQEBBhYJPIIlAQEBAwFAAQEsCwEECwsEBwMXISISAQUBChIGExKHXgMJCAMCCJ0OixOEUgEFklgDhWARBo57BAeEOJglgTGOeRgphFk X-IronPort-AV: E=Sophos;i="4.95,670,1384297200"; d="scan'208";a="53648539" Received: from mx5.janestreet.com (HELO tot-dmz-mxout1.janestreet.com) ([38.105.200.229]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 Jan 2014 08:55:45 +0100 Received: from tot-oib-smtp1.delacy.com ([172.27.22.15] helo=tot-smtp) by tot-dmz-mxout1.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1W44HH-0004gh-Cl for caml-list@inria.fr; Fri, 17 Jan 2014 02:55:43 -0500 Received: from tot-dmz-mxgoog1.delacy.com ([172.27.224.14] helo=mxgoog2.janestreet.com) by tot-smtp with esmtps (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1W44HH-0001Vd-Br for caml-list@inria.fr; Fri, 17 Jan 2014 02:55:43 -0500 Received: from mail-qc0-f177.google.com ([209.85.216.177]) by mxgoog2.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1W44HH-0007HI-90 for caml-list@inria.fr; Fri, 17 Jan 2014 02:55:43 -0500 Received: by mail-qc0-f177.google.com with SMTP id i8so3248838qcq.22 for ; Thu, 16 Jan 2014 23:55:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=UeZNkD6bXRt48K6T6ZFTZwukUeNtr3xyLN0fk4omo9A=; b=rUSoMIrcp5OH3FxfCZKgR5eby7gKDGIZwIapFLJC85/QvVqCojMIV37OnUscfwEcBK VkhprPDdpGsgEonjAQGjq6Fwq3ogAug/E7KWH6YfSv4fgk0ELW4IWhd9YebBEeafLSnV fptgt1WcCqCkeMNbctIUQDOnqg7h1094FLI3g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=UeZNkD6bXRt48K6T6ZFTZwukUeNtr3xyLN0fk4omo9A=; b=UopnpO3BnpceGONUS4lO2YVP7IVlQvgHkXoeU17p7+4nWB6F5+tCykS2OYba/qzAZC 5XxvC5mAq+/0dvt7y7p2MGVLRLFBdgcGURYRM9CAoJVgw3Con4XVBZAAXy/tsjMVNuPs xw19OFsLx/ssWoqJ2XiNHitqnMpQVgxTYcYD6xIc/zSY4Sm8qt+BJMJCqAEJUWELNvbe oAnJVy2uT/TTl5gqT21z6sIQGM3otlSm3xWAtpau5/PolVqSrSTFU6Ol+0HYsDdsDgxD WEw7VKEQVtYqVRnjBj7Vf7g6jx++idtuKnQDnd5UjdVOcVbwYgNNM4Tl9PpmqO30lbTa RBOQ== X-Gm-Message-State: ALoCoQkiGkc/2+XmWNaIPUMZ1fv87DcShqJknkEhp+1epwhNnGrY3HffjKvn4WnTQBt7cEmzYtrw/HySu2xUwQWgcXDBFoslaNtu2LawaTLYHJiylVFfdVphHfnBLTFxn2U7zP12HPE4CtP/iFDqeaJKJHtYDjwsrQ== X-Received: by 10.224.66.134 with SMTP id n6mr655773qai.39.1389945342857; Thu, 16 Jan 2014 23:55:42 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.224.66.134 with SMTP id n6mr655751qai.39.1389945342747; Thu, 16 Jan 2014 23:55:42 -0800 (PST) Received: by 10.140.89.47 with HTTP; Thu, 16 Jan 2014 23:55:42 -0800 (PST) In-Reply-To: <523666417617602473@orange.fr> References: <523666417617602473@orange.fr> Date: Fri, 17 Jan 2014 07:55:42 +0000 Message-ID: From: David House To: Damien Guichard Cc: Caml Mailing List Content-Type: multipart/alternative; boundary=001a11c2bd8469853a04f025de25 Subject: Re: [Caml-list] How much optimized is the 'a option type ? --001a11c2bd8469853a04f025de25 Content-Type: text/plain; charset=ISO-8859-1 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 for 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 = 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 > --001a11c2bd8469853a04f025de25 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
It behaves identically to that type.

It is just like any other sum type. However, due to the way that sum ty= pes are represented in memory, it is not that inefficient. The only thing t= hat makes it less efficient than a C pointer is the header block (necessary= for the GC). An option value always takes two words: one for the header, a= nd then either a pointer or a word that means "None".


On 17 J= anuary 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

--001a11c2bd8469853a04f025de25--