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 GAA17998; Tue, 9 Jul 2002 06:48:46 +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 GAA18312 for ; Tue, 9 Jul 2002 06:48:46 +0200 (MET DST) Received: from gato.phys.clemson.edu (gato.phys.clemson.edu [130.127.188.133]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g694mir20915; Tue, 9 Jul 2002 06:48:44 +0200 (MET DST) Received: from adsl-78-167-177.gsp.bellsouth.net ([216.78.167.177] helo=elefante.local) by gato.phys.clemson.edu with asmtp (Exim 3.35 #1 (Debian)) id 17Rmvb-0006Jy-00; Tue, 09 Jul 2002 00:48:43 -0400 Received: from oso.local ([192.168.1.3]) by elefante.local with esmtp (Exim 3.35 #1 (Debian)) id 17Rmw3-0001WF-00; Tue, 09 Jul 2002 00:49:11 -0400 Received: from fernando by oso.local with local (Exim 3.35 #1 (Debian)) id 17Rmw7-0003y1-00; Tue, 09 Jul 2002 00:49:15 -0400 Date: Tue, 9 Jul 2002 00:49:15 -0400 To: Xavier Leroy Cc: Fernando Alegre , caml-list@inria.fr Subject: Re: [Caml-list] finalizing bigarrays Message-ID: <20020709044915.GA15233@oso.local> References: <200207081448.QAA0000015136@beaune.inria.fr> <20020708105246.A10500@gaia.cc.gatech.edu> <20020708174813.D7941@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020708174813.D7941@pauillac.inria.fr> User-Agent: Mutt/1.3.28i From: Fernando Alegre Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk We need to use the stock Caml 3.04, and will not update until the next official Caml release, so unfortunately, the suggested use of Gc.finalise is out of the way until then. We opted for the cloning of bigarray_stubs.c. Our modified bigarray_custom_stubs.c is compiled into the application. It does not replace the original one, but supplements it. After dealing with some garbage collection weirdness that I'll comment in a separate message, we managed to make our custom bigarrays work. So everything is fine for us now. I'd still suggest that a "bigarray_alloc_with_finalizer" function would be a great addition to the standard bigarrays. It would make it so much easier for us users to interface Caml with C libraries... without having to reinvent the wheel each time. And while we are at it, I would also beg for a no-bounds-checked option for bigarrays. Then, the world will be perfect! :-) Thanks, Fernando On Mon, Jul 08, 2002 at 05:48:13PM +0200, Xavier Leroy wrote: > > 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