Re: [Rd] Destructive str(...)?

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Sun 31 Oct 2004 - 21:01:30 EST

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

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sun Oct 31 21:07:49 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:00:58 EST