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

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed Oct 6 19:00:31 CEST 1999


On Wed, 6 Oct 1999, Martin Maechler wrote:

[Pretty technical for R-help, so consider followups to R-devel.]

> However, here is the result of an experiment
>         [SunOS 5.5.1 Generic_103640-08 sun4u sparc SUNW,Ultra-2]
> 
> 			       SZ    RSS 
>  --vsize 10M --nsize 4M     96936  84656
>  --vsize 10M --nsize 3M     76456  64192
>   --vsize 9M --nsize 3M     75432  64192
>   --vsize 9M --nsize 2M     54952  43712
>   --vsize 9M --nsize 1M     34472  23232
>   --vsize 9M --nsize 1024K  34472  23232
>   --vsize 9M --nsize  800K  29992  18752
>   --vsize 9M --nsize  700K  27992  16752
>   --vsize 8M --nsize  700K  26968  16752
>   --vsize 5M --nsize  700K  23896  16752
> 
> 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.

So I think that we should change the order in the union vecsxp.

Note that some of the other elements of the union are triples of pointers, 
so I expect it to be 24 bytes on a 64-bit machine.

-- 
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