Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] finalizing bigarrays
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-08 (15:48)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] finalizing bigarrays
> 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) {
  } else {
    if (-- b->proxy->refcount == 0) {
  return Val_unit;

- Xavier Leroy
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: