caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Fernando Alegre <fernando@cc.gatech.edu>
To: Xavier Leroy <xavier.leroy@inria.fr>
Cc: Fernando Alegre <fernando@cc.gatech.edu>, caml-list@inria.fr
Subject: Re: [Caml-list] finalizing bigarrays
Date: Tue, 9 Jul 2002 00:49:15 -0400	[thread overview]
Message-ID: <20020709044915.GA15233@oso.local> (raw)
In-Reply-To: <20020708174813.D7941@pauillac.inria.fr>


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


  reply	other threads:[~2002-07-09  4:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-08 14:48 Damien Doligez
2002-07-08 14:52 ` Fernando Alegre
2002-07-08 15:48   ` Xavier Leroy
2002-07-09  4:49     ` Fernando Alegre [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-07-08 13:28 Fernando Alegre
2002-07-08 14:21 ` Olivier Andrieu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020709044915.GA15233@oso.local \
    --to=fernando@cc.gatech.edu \
    --cc=caml-list@inria.fr \
    --cc=xavier.leroy@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).