From: Shivkumar Chandrasekaran <shiv@ece.ucsb.edu>
To: caml-list@inria.fr
Cc: Damien Doligez <damien.doligez@inria.fr>
Subject: Re: [Caml-list] Weak pointers and Gc.finalise
Date: Thu, 1 Apr 2004 11:21:27 -0800 [thread overview]
Message-ID: <C5B487A0-8411-11D8-A952-000393942C76@ece.ucsb.edu> (raw)
In-Reply-To: <1E3A29A6-83FF-11D8-BD34-00039310CAE8@inria.fr>
On Apr 1, 2004, at 9:07 AM, Damien Doligez wrote:
>
>> (Side note: I am trying to avoid Marshaling the Bigarray unless it is
>> going to be garbage-collected. But if I cannot detect that, then I
>> have to always Marshal it whenever its entries change, which is very
>> inefficient.)
>
> I'm not sure I understand. The finalisation function is called when
> the value is about to be garbage-collected. Why can't you just
> marshal it at that point?
>
This session might explain what I am trying to do, and why I could not
do it.
-----------start session on Mac OS X 10.3.3---------------
Objective Caml version 3.07+2
# #load "bigarray.cma";;
# open Bigarray;;
# let fname = "Trashme.dat";;
val fname : string = "Trashme.dat"
# let final bat =
let fd = open_out_bin fname in
Marshal.to_channel fd bat [];
close_out fd;;
val final : 'a -> unit = <fun>
# let wt =
let wtt = Weak.create 1 in
let ba = Array1.create float64 c_layout 1000 in
Gc.finalise final ba;
Weak.set wtt 0 (Some ba);
wtt;;
val wt :
(float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Array1.t
Weak.t =
<abstr>
# Weak.check wt 0;;
- : bool = true
# Gc.compact ();;
- : unit = ()
# Weak.check wt 0;;
- : bool = false
# Sys.file_exists fname;;
- : bool = false
#
---------that's it-----------------------
As you can see my finalisation function on the bigarray tries to
marshal the data to a file. However, after Gc.compact the bigarray is
no longer reachable from anywhere in my code, but still, the
finalisation routine has not been called, as is evident from the
Sys.file_exists call. (I have also tried putting print_endline "Ha"
statements inside the finalisation routine to check this.)
I do see that Gc.full_major calls the finalisation calls. One way out
for me is to check if the data has been marshaled successfully,
otherwise I just issue a Gc.full_major call myself. However, I don't
want to exercise the GC unnecessarily.
Any advice? Thanks,
--shiv--
-------------------
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
prev parent reply other threads:[~2004-04-01 19:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-01 4:48 Shivkumar Chandrasekaran
2004-04-01 17:07 ` Damien Doligez
2004-04-01 19:21 ` Shivkumar Chandrasekaran [this message]
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=C5B487A0-8411-11D8-A952-000393942C76@ece.ucsb.edu \
--to=shiv@ece.ucsb.edu \
--cc=caml-list@inria.fr \
--cc=damien.doligez@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