caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: rich@annexia.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] CamlDL/Abstract pointers problem
Date: Fri, 30 Jan 2004 09:20:31 +0900	[thread overview]
Message-ID: <20040130092031V.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <20040129202404.GA15171@redhat.com>

From: Richard Jones <rich@annexia.org>
> 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


  parent reply	other threads:[~2004-01-30  0:20 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
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 [this message]
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=20040130092031V.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=rich@annexia.org \
    /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).