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
Disabling the OCaml garbage collector
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-11-27 (16:41)
From: Basile STARYNKEVITCH <basile@s...>
Subject: Re: [Caml-list] Disabling the OCaml garbage collector
Raj Bandyopadhyay wrote:
> Dear all
> I am writing a foreign function interface between OCaml and another 
> language (Python) which works via C. Since I have some memory issues 
> currently, I would like to be able to disable the OCaml Garbage 
> collector before jumping into C/Python, and re-enable it when I return 
> to OCaml.

I am not convinced it is possible or makes sense. More precisely, your 
foreign -coded in C, called by Ocaml code- function probably allocates 
some result, and this allocation can trigger the Ocaml garbage collector

In addition, AFAIK, the Ocaml minor garbage collector is only running 
when called,
either implicitly from some allocation routines, or explicitly.

So if you don't allocate things either directly or indirectly (e.g. by 
calling some callback coded in Ocaml) the Ocaml GC is not running.

> I am using the OCaml/C interface and the macros that it provides to 
> manage values (CAMLlocal and CAMLparam), but I would like to be able to 
> disable the GC entirely for short periods.

You definitely may need to hack the C code inside byterun/minor_gc.c 
(for example), but I don't understand what you want exactly.

However, I do know that mixing GCs, like Ocaml & Python, is a nightmare.
Did you consider having two separate Unix processes, one for the Ocaml 
code and one for the Python code, and having them communicate thru 
standard stuff like pipes, memory mapped files, ...

Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***