From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA12179 for caml-red; Tue, 12 Dec 2000 10:26:26 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA19543 for ; Tue, 12 Dec 2000 04:05:57 +0100 (MET) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id eBC35uv22023 for ; Tue, 12 Dec 2000 04:05:56 +0100 (MET) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id EAA07451 for caml-list@inria.fr; Tue, 12 Dec 2000 04:05:51 +0100 (MET) Date: Tue, 12 Dec 2000 04:05:50 +0100 From: Markus Mottl To: OCAML Subject: fancy GC question Message-ID: <20001212040549.A5381@miss.wu-wien.ac.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: weis@pauillac.inria.fr Hello, I am not sure whether the following "trick" is really safe, but it seems to work: When I allocate an integer array in OCaml, which is always boxed, both the pointers to and the elements are obviously contiguous in memory. One could exploit this in C-interfaces under the restriction that the array is never changed by the OCaml-runtime, e.g.: int *ar = (int *) &Field(v_ar, 0); And then one can read/write directly into the integer array without having to follow an indirection (an intermediate pointer) by treating "ar" as a normal C array. But is this really always safe if only C writes to the array? What about e.g. heap compactions and other GC-actions? Can other effects mess up the fact that the pointers map continuously on a contiguous chunk of memory (of integers)? If yes, this would, of course, require the traditional use of the "Field"-macro for every access. Otherwise, one could squeeze out a bit more performance in some (probably rare) cases. - Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl