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 RAA07477; Mon, 8 Jul 2002 17:48:21 +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 RAA07888 for ; Mon, 8 Jul 2002 17:48:21 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g68FmEv01078; Mon, 8 Jul 2002 17:48:14 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA07423; Mon, 8 Jul 2002 17:48:13 +0200 (MET DST) Date: Mon, 8 Jul 2002 17:48:13 +0200 From: Xavier Leroy To: Fernando Alegre Cc: caml-list@inria.fr Subject: Re: [Caml-list] finalizing bigarrays Message-ID: <20020708174813.D7941@pauillac.inria.fr> References: <200207081448.QAA0000015136@beaune.inria.fr> <20020708105246.A10500@gaia.cc.gatech.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20020708105246.A10500@gaia.cc.gatech.edu>; from fernando@cc.gatech.edu on Mon, Jul 08, 2002 at 10:52:46AM -0400 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Can Gc.finalise be used with externally allocated bigarrays? > I thought it worked only for Caml-allocated types. It does. However, a Caml bigarray value is actually a small block inside the Caml heap, containing pointers to the actual bigarray data. So, you can attach a finalization function to the Caml bigarray value. Presumably, this (Caml) function would call a C function that recovers the pointer to the actual bigarray data, then call your deallocation function on this pointer. Something along the lines below: value my_bigarray_finalize(value v) { struct caml_bigarray * b = Bigarray_val(v); if (b->proxy == NULL) { my_finalization_function(b->data); } else { if (-- b->proxy->refcount == 0) { my_finalization_function(b->proxy->data); stat_free(b->proxy); } } return Val_unit; } - Xavier Leroy ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners