From p.dalgaard at biostat.ku.dk  Sun Oct 31 11:01:30 2004
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Sun Oct 31 11:01:52 2004
Subject: [Rd] Destructive str(...)?
In-Reply-To: <6401039C-2AF1-11D9-B02D-0003938AF008@math.uni-augsburg.de>
References: <Pine.LNX.4.44.0410300859130.4649-100000@gannet.stats>
	<Pine.LNX.4.61.0410301104170.5261@itasca2.stat.uiowa.edu>
	<x2brejna59.fsf@biostat.ku.dk>
	<6401039C-2AF1-11D9-B02D-0003938AF008@math.uni-augsburg.de>
Message-ID: <x2r7nfkxz9.fsf@biostat.ku.dk>

Simon Urbanek <simon.urbanek@math.uni-augsburg.de> writes:

> Now, hold on a second - I thought the main point of EXTPTR is that the
> finalizer is called only once, that is when the last instance of the
> reference is disposed of by the gc (no matter how many copies existed
> meanwhile). Am I wrong and/or did I miss something? I did some tests
> which support my view, but one never knows ...

How do you ensure that the finalizer is called once? By *not* copying
the reference object! You can have as many references to it as you
like (i.e. assign it to multiple variables), and the object itself is
not removed until the last reference is gone, but if you modify the
object (most likely by setting attributes, but you might also change
the C pointer payload in a C routine), all "copies" are changed:

> x <- as.tclObj(pi)
> x
<Tcl> 3.14159265359
> y <- x
> y
<Tcl> 3.14159265359
> mode(x)
[1] "externalptr"
> attr(x, "Simon") <- "Urbanek"
> attributes(y)
$class
[1] "tclObj"

$Simon
[1] "Urbanek"



-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907


[Rd] Destructive str(...)?
Peter Dalgaard