From tlumley at u.washington.edu  Mon Aug 24 17:20:44 2009
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Mon, 24 Aug 2009 08:20:44 -0700 (PDT)
Subject: [Rd] Basic Question regarding PROTECT
In-Reply-To: <1e7471d50908240633u5db73463u3dc31a45e25d2656@mail.gmail.com>
Message-ID: <Pine.LNX.4.43.0908240820440.26977@hymn14.u.washington.edu>

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



[Rd] Basic Question regarding PROTECT
Thomas Lumley