What size is a cons cell? (was [R] R --nsize 2M runs havoc (under linux))

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Oct 6 21:20:13 CEST 1999


Prof Brian D Ripley <ripley at stats.ox.ac.uk> writes:

> > Which indicates
> > 1) --vsize uses byte units as ?Memory says
> > 2) --nsize has `Ncell' units which now seem to use 
> >    20 bytes each.. instead of 16
> > 
> >    which *is* 20% -- why??
> 
> Note: it is machine dependent, and it is 16 on Linux, for me (and the
> subject was about Linux).
> 
> Answer: A `cons cell' is internally a SEXPREC, and it
> allocates by
> 
>     if (!(R_NHeap = (SEXPREC *) malloc(R_NSize * sizeof(SEXPREC))))
> 
> What size is a SEXPREC?  It is a union, and one element of the union is
> int+(union including double) + int.  On some 32-bit machines alignment will
> give int+4bytes padding+union+int.

Er, am I of my rocker, or..? I get

flags: 32 bits
attributes: pointer
u: union, 3 pointers/pointer and 2 ints/1 int

on a 32bit system, that makes 5 * 4 bytes with no padding... The "16
bytes" is simply wrong, and must have been ever since attributes was
introduced. On a 64 bit system one gets 36 or 40 bytes depending on
whether it is possible to use 32 bit ints for the flags. Actually, I
don't think that the 16 bits in the gp fields in the flags structure
is actually doing anything, so perhaps that could be a short int, but
I doubt that you'd gain anything from it.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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