[R] Object size in bytes

Nicholas Lewin-Koh kohnicho at comp.nus.edu.sg
Sat Sep 2 06:27:30 CEST 2000


Thanks,
I think i threw this one out off the cuff without thinking about it too
deeply. What I had in mind was to compare the same data stored in two
different formats to see which was more space efficient.

So to rephrase my question.
for a set of doubles (say two columns) and some information about them
which storage mode would be the most efficient:
a single listwith the attributes and columns as elements of the list.
a matrix with attributes.
a list with attributes.

So I believe fo my question Dr. Ripley's points are very pertinent. Which
structures have more overhead.

Thank you again
for the informative fast replies.

Nicholas
On Fri, 1 Sep 2000, Prof Brian D Ripley wrote:

> 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