English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Troubles with C->Caml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-10-21 (03:23)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] Troubles with C->Caml

On Sun, Oct 21, 2001 at 03:36:04AM +0400, malc wrote:

>     result = alloc_small (1, 2);
>     Field (result, 0) = <some value>;
>     Field (result, 1) = Extract_exception (res);

FAQ. When calling allocating functions, the GC may move the values of
the heap. The variable "res", of type "value", is actually a pointer
to the heap. After the call to "alloc_small", its pointed value may
have been moved by the GC, but "res" still points to the old area.

The OCaml documentation explains you this point. You have to add
specific code in the beginning and at the end of your function to tell
the GC that you are using some variables of type "value". The functions
to call have names CAMLparam, CAMLlocal, CAMLreturn, things like that,
defined in "caml/memory.h".

Read the documentation carefully because if you don't program it
correctly, you can get memory fault at any time later.

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