[Rd] DUP=FALSE

Thomas Lumley tlumley@u.washington.edu
Mon, 26 Mar 2001 14:58:10 -0800 (PST)


On Mon, 26 Mar 2001, Paul Gilbert wrote:

> Thomas
>
> Thanks for verifying that this actually does work the way you thought it
> did. In the example I asked about  (qr.qty ) I am fairly sure that it
> does not modify the y argument. Unfortunately this seems relatively
> difficult to trace for certain, and experimenting works but may not hit
> all cases.
>
> Another thing I find I do not understand is how many copies of an
> argument are made. For example, in a call to a function like
>
> f <- function(x){ .C("goodidea", y=double(1),  x, DUP=TRUE)[[y]] }
>
> there is the original x and the duplicated x in the argument to .C, but
> is there a third in the list returned by .C, or is that somehow the same
> one as in the argument to .C.  My problem is that my x is very big.

There's a third one. In dotcode.c the following happens

a) x is copied to a C array at the top of the R heap
b) the C function is called
c) the C array is copied into a newly created R object
d) this new R object is returned.

You only have three copies for a very short time, since the C array is
freed as soon as the new R object is returned.

A more selective version of DUP would be nice, but the only real way to do
it at the moment is to write a wrapper using .Call or .External and do any
necessary copying yourself.

I don't know why you are getting slightly different results with
DUP=FALSE. I can't think of any good explanation.

	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._