Re: [Rd] Use of Rf_duplicate

From: Oleg Sklyar <osklyar_at_ebi.ac.uk>
Date: Tue, 29 May 2007 14:52:24 +0100

> PROTECT(y=x); and
This has no sense as y is just the same pointer as x. By doing this you did not create any new data, if you modify y, x will be modified. y does not need protection as x is probably protected.

> PROTECT (y = duplicate(x)); ?
This will allocate new memory for data in x and copy data over there. This is correct, modifying y will not modify x. And y needs protection as it is newly allocated.

> PROTECT(y = duplicate(x));
> PROTECT(z = duplicate(VECTOR_ELT(y,2)));
It is not clear what you want to achieve by this. z will not be part of y any more

> PROTECT(y=duplicate(x));
> PROTECT(z = VECTOR_ELT(y,2));
The correct way would be

PROTECT(y=duplicate(x));
z = VECTOR_ELT(y,2);

as you do not need to protect z, it is done by protecting y

> And if I did create a duplicate, is there a way to destroy it manually
> before the end of the function, rather than rely on on the R garbage
> collector?
Not that I know about.

Best,
Oleg

-- 
Dr Oleg Sklyar | EBI-EMBL, Cambridge CB10 1SD, UK | +44-1223-494466

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 29 May 2007 - 14:03:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 May 2007 - 07:34:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.