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 BAA10659; Fri, 30 Jan 2004 01:20:36 +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 BAA10304 for ; Fri, 30 Jan 2004 01:20:35 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i0U0KXv09892 for ; Fri, 30 Jan 2004 01:20:34 +0100 (MET) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id JAA04630; Fri, 30 Jan 2004 09:20:27 +0900 (JST) In-Reply-To: <20040129202404.GA15171@redhat.com> References: <20040129192641.GA12533@redhat.com> <20040129202404.GA15171@redhat.com> Subject: Re: [Caml-list] CamlDL/Abstract pointers problem To: rich@annexia.org Cc: caml-list@inria.fr X-Mailer: Mew version 1.94.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20040130092031V.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 30 Jan 2004 09:20:31 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 pointers:01 jacques:01 2004:99 alain:01 frisch:01 fahndrich:01 malloc:01 pointers:01 self-evident:01 jacques:01 ocaml:01 ocaml:01 garrigue:01 garrigue:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Richard Jones > On Thu, Jan 29, 2004 at 08:55:16PM +0100, Alain.Frisch@ens.fr wrote: > > Reference: http://pauillac.inria.fr/~doligez/caml-guts/Fahndrich99.txt > > Interesting. Can someone who knows about the guts of OCaml comment on > this: Does OCaml store simply the start and extent of the "ML Heap"? > Or does it know about individual blocks of ML heap and use some sort > of tree structure to work out if a pointer points into the heap? > > I could imagine a scenario like this: > > +---------+ > | ML | > | Heap | > | | > | ---------\ > | | | > +---------+ | > | > +---------+ | > | C |<--/ > | malloc | > +---------+ > > +---------+ > | More | > | ML | > | Heap | > | | > +---------+ > > If OCaml only knew about the start and extent of the ML heap, then it > might think that the pointer to the C-allocated space lies within the > ML heap. Fortunately, ocaml is clever enough to properly determine what is the ML heap. However, there is another scenario which could cause you problems: if for some reason your C pointer get freed, and later the ML heap is extended so that it includes the address of the pointer, then you may have some pointers left on the ML which will now be seen as ML pointers. +---------+ | ML | | Heap | | | | ---------\ | | | +---------+ | | +---------+ | | More ML |<--/ | Heap | +---------+ Some people have got problems with that. So the safe rule is: only use "raw" C pointers (not wrapped in a custom block) when you are sure the pointed block will not be freed. But this is self-evident: if the pointed block is managed, then you should probably have a custom block to cooperate with C memory management anyway. Jacques Garrigue ------------------- 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