caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <markus.mottl@gmail.com>
To: Tom Ridge <tom.j.ridge+caml@googlemail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] String, Array, Bigarray.char
Date: Thu, 9 May 2013 10:25:28 -0400	[thread overview]
Message-ID: <CAP_800rdzNh=hSkCykZHddn-ShpxTAfnC_rj8qdvRNe6vyX0yg@mail.gmail.com> (raw)
In-Reply-To: <CABooLwO=eYqxFQNJHUKFV_u-11R9b0U=BjH0OaGf--Uai457zQ@mail.gmail.com>

On Thu, May 9, 2013 at 9:32 AM, Tom Ridge
<tom.j.ridge+caml@googlemail.com> 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

  parent reply	other threads:[~2013-05-09 14:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-09 13:32 Tom Ridge
2013-05-09 13:44 ` Anil Madhavapeddy
2013-05-09 14:07   ` Tom Ridge
2013-05-09 14:14     ` Tom Ridge
2013-05-09 14:21       ` Anil Madhavapeddy
2013-05-09 14:30         ` Tom Ridge
2013-05-09 16:29         ` ygrek
2013-05-09 14:29       ` Markus Mottl
2013-05-09 14:25 ` Markus Mottl [this message]
2013-05-10 23:42 ` 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='CAP_800rdzNh=hSkCykZHddn-ShpxTAfnC_rj8qdvRNe6vyX0yg@mail.gmail.com' \
    --to=markus.mottl@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=tom.j.ridge+caml@googlemail.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).