From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA20368; Fri, 1 Jun 2001 00:13:09 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA20288 for ; Fri, 1 Jun 2001 00:13:08 +0200 (MET DST) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f4VMD1f21798; Fri, 1 Jun 2001 00:13:01 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id AAA14567; Fri, 1 Jun 2001 00:13:01 +0200 Date: Fri, 1 Jun 2001 00:13:01 +0200 From: Daniel de Rauglaudre To: Harry Chomsky Cc: Caml list Subject: Re: [Caml-list] Win32 API Message-ID: <20010601001301.A11836@verdot.inria.fr> References: <00c301c0ea11$17a38570$22f65140@w2kpro> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0us In-Reply-To: <00c301c0ea11$17a38570$22f65140@w2kpro>; from harry@chomsky.net on Thu, May 31, 2001 at 01:34:29PM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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