[
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: | Daniel de Rauglaudre <daniel.de_rauglaudre@i...> |
| Subject: | Re: [Caml-list] Win32 API |
Hi,
On Thu, May 31, 2001 at 01:34:29PM -0700, Harry Chomsky wrote:
> I've embarked on a project to enable writing full-fledged Win32 applications
> using OCaml. I'm doing this mostly for fun as I take a break between jobs.
> [...]
> http://www.speakeasy.org/~hchomsky/ocaml-win32.html
> [...]
> The main area I'm uncomfortable with is memory management and the section of
> [...]
As far as I read your C code, you are likely to have problems with the
OCaml GC: you risk unexpected Memory Faults or Bus Errors. When you
call an OCaml alloc function, all your variables of type "value" may
point to wrong places. E.g. if you write:
some_function (value x)
{
value y;
y = alloc_tuple(2);
...
}
The "alloc_tuple" may call the GC: and the GC may move the other OCaml
allocated values. If the parameter x corresponds to a pointer (i.e. not
an integer), its value may become false after the allocation of y (may
or may not). The correct way is to previously inform the GC that it
has to change the value of the variable x if it changes the location
of the values it refers to.
This can (must) be done by the macros defined in the module memory.h.
The correct way (if I am not wrong) to write this function like this:
some_function (value x)
{
CAMLparam1(x);
value y;
y = alloc_tuple(2);
...
}
--
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr