Basic Question regarding PROTECT
On Mon, 24 Aug 2009, Saptarshi Guha wrote:
Thank you. So the reason I wouldnt need to protect y had I returned to
R, is because had i had done something like
h<-.Call("boo",a)
where "boo" contains y=foo()
the assignment "<-" to h would have a PROTECT somewhere, i.e R's
assignment is doing the protection for me.
Had I not returned to R, I would have to do it myself.
Yes PROTECT is quite cheap, I had thought it to be costly but 1MM
PROTECT/UNPROTECT calls, takes <1 second (on a macbook 2.16ghz)
That's not where the cost would be. PROTECT/UNPROTECT calls themselves are very cheap, since they just push and pop pointers from a stack. Any real impact of different strategies in using PROTECT would be seen in the garbage collector.
-thomas
Thomas Lumley Assoc. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle