caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: OCAML <caml-list@inria.fr>
Subject: fancy GC question
Date: Tue, 12 Dec 2000 04:05:50 +0100	[thread overview]
Message-ID: <20001212040549.A5381@miss.wu-wien.ac.at> (raw)

Hello,

I am not sure whether the following "trick" is really safe, but it seems
to work:

When I allocate an integer array in OCaml, which is always boxed, both
the pointers to and the elements are obviously contiguous in memory.
One could exploit this in C-interfaces under the restriction that the
array is never changed by the OCaml-runtime, e.g.:

  int *ar = (int *) &Field(v_ar, 0);

And then one can read/write directly into the integer array without
having to follow an indirection (an intermediate pointer) by treating
"ar" as a normal C array.

But is this really always safe if only C writes to the array? What about
e.g. heap compactions and other GC-actions? Can other effects mess up the
fact that the pointers map continuously on a contiguous chunk of memory
(of integers)?

If yes, this would, of course, require the traditional use of the
"Field"-macro for every access. Otherwise, one could squeeze out a bit
more performance in some (probably rare) cases.

- Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl



             reply	other threads:[~2000-12-12  9:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-12  3:05 Markus Mottl [this message]
2000-12-12 15:38 ` Xavier Leroy
2000-12-13 23:06   ` Markus Mottl
2000-12-12 12:18 Damien Doligez
2000-12-14 22:10 Markus Mottl

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=20001212040549.A5381@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=caml-list@inria.fr \
    /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).