Re: [Rd] Understanding tracemem

From: Hadley Wickham <hadley_at_rice.edu>
Date: Thu, 12 Jul 2012 10:49:50 -0700

> The list gets copied, but do a and b, or does the new list point to
> the existing locations? The following test suggests that it's a deep
> copy.
>
> x <- 1:1e7
> z <- list(a = x)
>
> system.time(replicate(100, z$b <- 1L)) / 100
> # ~ 0.05s
> system.time(replicate(100, x[1e6 + 1L] <- 1L)) / 100
> # ~ 0.04s

But that should be

system.time(replicate(100, x[1e7 + 1L] <- 1L)) / 100 # ~0.10s
system.time(replicate(100, z$b <- 1L)) / 100 # ~ 0.04s

which suggests that it's not a deep copy.

But

x <- 1:1e6
z <- list(a = x)
system.time(replicate(100, z$b <- 1L)) / 100 # ~0.005s

which suggests it's not a shallow copy either.

But then neither of those are probably good tests because they modify in place. I'll think more.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu 12 Jul 2012 - 17:52:44 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Sat 14 Jul 2012 - 01:30:31 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.

list of date sections of archive