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 8650C7EE51 for ; Thu, 9 May 2013 16:25:35 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of markus.mottl@gmail.com) identity=pra; client-ip=74.125.82.44; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="markus.mottl@gmail.com"; x-sender="markus.mottl@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of markus.mottl@gmail.com designates 74.125.82.44 as permitted sender) identity=mailfrom; client-ip=74.125.82.44; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="markus.mottl@gmail.com"; x-sender="markus.mottl@gmail.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@mail-wg0-f44.google.com) identity=helo; client-ip=74.125.82.44; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="markus.mottl@gmail.com"; x-sender="postmaster@mail-wg0-f44.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuABABSxi1FKfVIsjWdsb2JhbABSgz7ABnIIFg4BAQEBBwsLCRIGJIIfAQEFQAEUBx0BAwwGBQsNLiEBAREBBQEcBhOHeQEDD6BVjD2CfoRZChknDViHMgEFDIxGglYHg1UDlUiBZIwTgz0WKYRRIA X-IPAS-Result: AuABABSxi1FKfVIsjWdsb2JhbABSgz7ABnIIFg4BAQEBBwsLCRIGJIIfAQEFQAEUBx0BAwwGBQsNLiEBAREBBQEcBhOHeQEDD6BVjD2CfoRZChknDViHMgEFDIxGglYHg1UDlUiBZIwTgz0WKYRRIA X-IronPort-AV: E=Sophos;i="4.87,641,1363129200"; d="scan'208";a="16646223" Received: from mail-wg0-f44.google.com ([74.125.82.44]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 09 May 2013 16:25:35 +0200 Received: by mail-wg0-f44.google.com with SMTP id z12so3133564wgg.35 for ; Thu, 09 May 2013 07:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=c6AlFe50OA38dyTKa0HjOiKNc1Wdz++NQJ9ibZkO73M=; b=wkBX/1qbHsDzRvQV4wQWWFJysKXw71aTRZyMKPPbV4VKhYydttKZ8/JL6r2+Vxedw6 SxZS1Ll+oXf2kauqX30ovZYpcaWUWIRR4bvfE459Q5/D0pigGern4iPk5GMOV51P9+bi qMnb154nLj3CkiJ6AjBqxDgHedv2mWYPuxhquMRKDWm+OngS6K2RTjgsMOkwRn1sea3m mvpDZZ1XSBR+p0sPK0Oy6wKbs+yolBKkyEgTPgiKJcKLdS3d6kSSCmCwj4kFQkG94aGi mJ2W2Hywq/4tmvc51oFodT/stlHhtJTLWLCg1pDNDrgRhZvTyV1uyNOGrTyYy/eemENn qMxA== MIME-Version: 1.0 X-Received: by 10.180.210.225 with SMTP id mx1mr29553132wic.15.1368109528731; Thu, 09 May 2013 07:25:28 -0700 (PDT) Received: by 10.194.46.9 with HTTP; Thu, 9 May 2013 07:25:28 -0700 (PDT) In-Reply-To: References: Date: Thu, 9 May 2013 10:25:28 -0400 Message-ID: From: Markus Mottl To: Tom Ridge Cc: caml-list Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] String, Array, Bigarray.char On Thu, May 9, 2013 at 9:32 AM, Tom Ridge wrote: > This presumably takes O(n) time (where n is the length of the string > bs). My question is: is there functionality to move values between > these types at cost O(1)? Basically, I'm hoping that String is > implemented as A.of_array Bigarray.char Bigarray.c_layout or > similar... This is unfortunately impossible, because OCaml-strings live in the OCaml-heap, whereas the contents of bigstrings (i.e. bigarrays of chars) live in the C-heap. The Jane Street Core library has a Bigstring module in Core.Std.Bigstring, which builds on bigarrays of the same type that you are using here. This Bigstring-module also features functions for converting and blitting ordinary OCaml strings to bigstrings. The "workhorse" function for that purpose is written in C and uses memcpy, which is as fast as one could hope for. It also supports all functions that the standard String-module offers so you shouldn't have to convert back and forth between strings and bigstrings in the first place. Regards, Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com