Browse thread
[Caml-list] GC and interoperability with C
-
Alexander V. Voinov
-
Jacques Garrigue
- Alexander V. Voinov
- Alexander V. Voinov
-
Jacques Garrigue
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Alexander V. Voinov <avv@q...> |
| Subject: | Re: [Caml-list] GC and interoperability with C |
Hi All,
Jacques Garrigue wrote:
> Either these values are long ints, and you can just copy them, or they
> are pointers, and you just do as I explained.
>
> value my_func(value a, value b)
> {
> value *loca = (value*)malloc(sizeof(value));
> value *locb = (value*)malloc(sizeof(value));
> *loca = a; *locb = b;
> register_global_root(loca);
> register_global_root(locb);
>
> ....
> }
>
> Now you can put loca and locb directly in you C data structure, the
> real data being accessed by *loca, *locb.
>
> Of course, don't forget that you must unregister your global roots
> before freeing loca and locb.
I've played a bit with this, and I have an observation that huge amount
of time is spent on remove_global_root(a).
I will describe the problem, to let you better understand to context. I
have an implementation of B+-tree, with threading, allowing duplicates
and logarithmic access to the item number. Of course it would be fun to
reimplement it in OCaml, but I have enough fun besides this, and enough
serious tasks for which specifically I started to consider OCaml; also,
I'd like to see on this example how much could I get in the interaction
between C and OCaml; next, the module is tested and used for years, and
I see no point to duplicate the work. If successful, I'd like to make it
available for OCaml community.
I store arbitrary OCaml objects in the nodes of the tree, using the
advice quoted above. And I see that the performance of an application is
very different with and without remove_global_root(a). Am I doing
something wrong (besides the very idea of building a complex C
structure, containing lots of OCaml objects; let's assume that the idea
is justified in this or that case)?
Thank you in advance
Alexander
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr