<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/d0bd306032bce489eca958a71cda585c"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-07-08T15:48:21"
  subject="Re: [Caml-list] finalizing bigarrays"
  prev="2002/07/e869a5f1f6d1ae8278108425d54bf213"
  next="2002/07/f49c4126b9e8f96224a3185f0b93557f"
  prev-in-thread="2002/07/e869a5f1f6d1ae8278108425d54bf213"
  next-in-thread="2002/07/f9f4a8f9991df7c7143419e673d0dbe1"
  prev-thread="2002/07/7e2792e8388e42aaaa374716c37998e6"
  next-thread="2002/07/41955c135ff961fc69a8edb83b7357d5"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Re: [Caml-list] finalizing bigarrays">
<msg 
  url="2002/07/d84193189834bb0b419bebbe8b34fe34"
  from="Damien Doligez &lt;damien.doligez@i...&gt;"
  author="Damien Doligez"
  date="2002-07-08T14:48:31"
  subject="Re: [Caml-list] finalizing bigarrays">
<msg 
  url="2002/07/e869a5f1f6d1ae8278108425d54bf213"
  from="Fernando Alegre &lt;fernando@c...&gt;"
  author="Fernando Alegre"
  date="2002-07-08T14:52:50"
  subject="Re: [Caml-list] finalizing bigarrays">
<msg 
  url="2002/07/d0bd306032bce489eca958a71cda585c"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-07-08T15:48:21"
  subject="Re: [Caml-list] finalizing bigarrays">
<msg 
  url="2002/07/f9f4a8f9991df7c7143419e673d0dbe1"
  from="Fernando Alegre &lt;fernando@c...&gt;"
  author="Fernando Alegre"
  date="2002-07-09T04:48:46"
  subject="Re: [Caml-list] finalizing bigarrays">
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
&gt; Can Gc.finalise be used with externally allocated bigarrays?
&gt; 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-&gt;proxy == NULL) {
    my_finalization_function(b-&gt;data);
  } else {
    if (-- b-&gt;proxy-&gt;refcount == 0) {
      my_finalization_function(b-&gt;proxy-&gt;data);
      stat_free(b-&gt;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

</contents>

</message>

