caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@tpg.com.au>
To: Richard Jones <rich@annexia.org>
Cc: ronniec95@lineone.net, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] CamlDL/Abstract pointers problem
Date: 30 Jan 2004 06:04:41 +1100	[thread overview]
Message-ID: <1075403080.3632.80.camel@localhost.localdomain> (raw)
In-Reply-To: <20040129150209.GB30750@redhat.com>

On Fri, 2004-01-30 at 02:02, Richard Jones wrote:
> On Thu, Jan 29, 2004 at 01:06:39PM +0000, ronniec95@lineone.net wrote:
> > All I want to do is just give Ocaml a pointer to something I've created
> > in C and pass it back to other C functions later; don't want it to do anything
> > with it (including moving it around the ocaml heap).\
> 
> It's my understanding that you can't just pass a pointer back to OCaml
> and cast it to a value.  OCaml will think that the pointer points to
> an OCaml heap object, and hence try to examine / move / delete it in
> the garbage collector. 

Nope: RTFM:

                                  18.2
                                  The value type
All Caml objects are represented by the C type value, defined in the
include file caml/mlvalues.h, along with macros to manipulate values of
that type. An object of type value is either: 
      * an unboxed integer;
      * a pointer to a block inside the heap (such as the blocks
        allocated through one of the alloc_* functions below);
      * a pointer to an object outside the heap (e.g., a pointer to a
        block allocated by malloc, or to a C variable).

18.2.3 Pointers outside the heap

Any word-aligned pointer to an address outside the heap can be safely
cast to and from the type value. This includes pointers returned by
malloc, and pointers to C variables (of size at least one word) obtained
with the & operator.

[Note the manual is wrong here in that a C variable of word
size need not be word aligned .. it isn't necessary on x86 machines,
x86 doesn't require integers or addresses to be aligned..however
most C compilers do the alignment anyhow because it 
improves performance. I think floats do have to be aligned though,
and thus malloc must return an even address] 

-- 
John Max Skaller, mailto:skaller@tpg.com.au
snail:25/85c Wigram Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850. Checkout Felix: http://felix.sf.net




-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2004-01-29 19:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-29 13:06 ronniec95
2004-01-29 15:02 ` Richard Jones
2004-01-29 15:52   ` ronniec95
2004-01-29 16:32     ` art yerkes
2004-01-29 19:04   ` skaller [this message]
2004-01-29 19:26     ` Richard Jones
2004-01-29 19:55       ` Alain.Frisch
2004-01-29 20:24         ` Richard Jones
2004-01-29 23:07           ` David Brown
2004-01-30  0:20           ` Jacques Garrigue
2004-01-30  7:04             ` Brian Hurt
2004-01-30 15:36               ` Jacques Garrigue
2004-01-30 16:52                 ` Brian Hurt
2004-01-30 20:56               ` skaller

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=1075403080.3632.80.camel@localhost.localdomain \
    --to=skaller@tpg.com.au \
    --cc=caml-list@inria.fr \
    --cc=rich@annexia.org \
    --cc=ronniec95@lineone.net \
    /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).