[R] Object size in bytes
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Fri Sep 1 17:58:54 CEST 2000
On 1 Sep 2000, Peter Dalgaard BSA wrote:
> Nicholas Lewin-Koh <kohnicho at comp.nus.edu.sg> writes:
>
> > Hi,
> > Is there a command that will give the total size of an R object in bytes?
>
> No. You can get some of the way with
>
> function (it)
> {
> x1 <- gc()[, 1]
> copy <- it
> x2 <- gc()[, 1]
> x1 - x2 - c(5, 6) # correct for variables and function call (fudged)
> }
>
> > x<-rnorm(20000)
> > sizeit(x)
> Ncells Vcells
> 1 20000
> > names(x)<-1:20000
> > sizeit(x)
> Ncells Vcells
> 3 30001
>
> And from there on things become system dependent. On x386 (Linux and
> also Windows IIRC) an Ncell is 20 bytes and a Vcell is 8.
Isn't this going to fail in 1.2.0? Not only is the workspace size
not fixed, but also the garbage collector does not clean out in one pass.
(And the size of Ncells changes with that version.)
Also, to what extent does R share parts of objects (e.g. lists) without
copying them? (S does quite extensively.)
I would have thought one reasonable approximate answer was to dump the
object in binary save format and look at the file size.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list