From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA24802; Thu, 29 Jan 2004 20:04:02 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA25150 for ; Thu, 29 Jan 2004 20:04:00 +0100 (MET) Received: from mail5.tpgi.com.au (mail.tpgi.com.au [203.12.160.100]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i0TJ3wv03377 for ; Thu, 29 Jan 2004 20:03:59 +0100 (MET) Received: from 203-219-225-179-syd-ts24-2600.tpgi.com.au (203-219-225-179-syd-ts24-2600.tpgi.com.au [203.219.225.179]) by mail5.tpgi.com.au (8.12.10/8.12.10) with ESMTP id i0TJ3UwZ017405; Fri, 30 Jan 2004 06:03:33 +1100 Subject: Re: [Caml-list] CamlDL/Abstract pointers problem From: skaller Reply-To: skaller@tpg.com.au To: Richard Jones Cc: ronniec95@lineone.net, caml-list In-Reply-To: <20040129150209.GB30750@redhat.com> References: <40169E8D00006067@mk-cpfrontend-1.mail.uk.tiscali.com> <20040129150209.GB30750@redhat.com> Content-Type: text/plain Message-Id: <1075403080.3632.80.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 30 Jan 2004 06:04:41 +1100 Content-Transfer-Encoding: 7bit X-TPG-Antivirus: Passed X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 pointers:01 tpg:99 2004:99 2004:99 ronniec:01 lineone:01 rtfm:01 mlvalues:01 unboxed:01 alloc:01 malloc:01 pointers:01 word-aligned:01 malloc:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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