Skip to content
Prev 3420 / 398500 Next

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

On Wed, 6 Oct 1999, Martin Maechler wrote:
[Pretty technical for R-help, so consider followups to R-devel.]
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.