[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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) {
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