Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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:  FAQ:
To unsubscribe, mail  Archives: