dear R experts: I am curious again about R memory allocation strategies.
Consider an intentionally inefficient program:
ranmatme <- function( lx, rx ) {
m <- matrix(NA, nrow=lx, ncol=rx)
for (li in 1:rx) {
cat("\tLag i=", li, "object size=", object.size(m), "\n")
m[,li] <- rnorm(lx)
}
m
}
v <- ranmatme( 1024*1024*128, 3 )
[1] on the first cat, the object size is only 1.6GB, which is half the size
of the 3.2GB that it is on the 2nd and 3rd call. why?
[2] I tried to monitor the linux memory allocation in another window. I
could be completely wrong, but it seems that upon function exit, memory
usage spikes briefly. it is almost as if there was an explicit copy of m
into v, and both had to exist simultaneously for a moment in time. is this
the case? (if so, is there a way to return and assign just the reference?
I may be blanking here---maybe the answer is obvious.)
regards,
/iaw
----
Ivo Welch ([email protected])
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.