From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 1D70E7EC6E for ; Mon, 27 Jan 2014 11:03:58 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.15.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=mailfrom; client-ip=212.227.15.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.15.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqUCAPMt5lLU4w8EnGdsb2JhbABZux6FT4EKFg4BAQEBAQYNCQkUKIIlAQEBBDo/EAsYCSUPBSghiAMBGMIBH4YOF48NB4MkgRQEmCaGMRKPCg X-IPAS-Result: AqUCAPMt5lLU4w8EnGdsb2JhbABZux6FT4EKFg4BAQEBAQYNCQkUKIIlAQEBBDo/EAsYCSUPBSghiAMBGMIBH4YOF48NB4MkgRQEmCaGMRKPCg X-IronPort-AV: E=Sophos;i="4.95,728,1384297200"; d="scan'208";a="54980505" Received: from mout.web.de ([212.227.15.4]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 27 Jan 2014 11:03:57 +0100 Received: from frosties.localnet ([37.49.32.119]) by smtp.web.de (mrweb001) with ESMTPSA (Nemesis) id 0Mg7Zl-1VtmZ732UX-00NSDQ for ; Mon, 27 Jan 2014 11:03:56 +0100 Received: from mrvn by frosties.localnet with local (Exim 4.80) (envelope-from ) id 1W7j2p-0006ee-S3; Mon, 27 Jan 2014 11:03:55 +0100 Date: Mon, 27 Jan 2014 11:03:55 +0100 From: Goswin von Brederlow To: Jon Harrop Cc: 'Yotam Barnoy' , 'Ocaml Mailing List' Message-ID: <20140127100355.GD24902@frosties> References: <20140120101654.GI26447@frosties> <08bc01cf17b8$9263d070$b72b7150$@ffconsultancy.com> <20140123092925.GB20624@frosties> <01c401cf1891$b1fb1360$15f13a20$@ffconsultancy.com> <026101cf18dd$756c13d0$60443b70$@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <026101cf18dd$756c13d0$60443b70$@ffconsultancy.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Provags-ID: V03:K0:H5vQEqaOjzIaWbPQrH36uorV0k7XCpl4rrQ9yL//liuUU6pMmmV Gdy1Qp+feRhfo+/quTWvT8AfIYO+774VcLSPnDB7438/bC7GVGJMDma3/F8+vxvsypPixG3 xIgSS9im1MYcmmseeOVequK7R/BJLvYvYUb6CYoKF44OizxIGOSb4L7ZkOc6Vq8ZsOkUhEB bXYTn4ktLtxhdxyQ5Rlfw== Subject: Re: [Caml-list] How much optimized is the 'a option type ? On Fri, Jan 24, 2014 at 08:22:43AM -0000, Jon Harrop wrote: > Yotam wrote: > > Just to clarify, by value types you mean stuff allocated on the stack, > right? > > A value type is just an unboxed type like a C struct. A local variable of a > value type is stored on the stack. A field inside a heap-allocated object > that is a value type is stored inside the object and not in a separate > object. An array of value types is a single contiguous block of memory with > no pointers (e.g. an array of complex numbers). > > With value types you can almost completely avoid the garbage collector by > replacing pointers with indices into an array of value types that acts as a > pool allocator. This can be useful for avoiding GC latency and for > optimizing for collections that violate the generational hypothesis (e.g. > long-lived Sets and Maps). > > In HLVM, tuples were value types. For example, an (int * float) array is > represented as a single contiguous block of memory. In constrast, OCaml > represents this is an array of pointers to pairs where the second element is > another pointer to a boxed float. > > Value types and reified generics permit very efficient hash tables. For > example, the Dictionary type on .NET does not contain any > pointers. > > Cheers, > Jon. Problem is that a value is a fixed size and fits in a register. A tuple does not. (int * float) even takes the space of 3 values on 32bit. You can unbox that in the optimizer for local use but in memory and in function calls you need to pass this as box. Otherwise polymorphic functions break. Putting larger structures into an array without boxing also only works for immutable objects and by copying them every time they are passed around. You can't copy a mutable and you can't pass a pointer to the middle of an array to another function or the GC might freak out. So you have to be verry carefull where you use those unboxed arrays. They only works within a single module like a Hashtbl. MfG Goswin