[Rd] Why does an empty vector occupy 40 bytes?

Hadley Wickham h.wickham at gmail.com
Thu Aug 29 18:08:35 CEST 2013

> You have not: the start of the vector area also needs to be aligned (since
> it might hold doubles or CHARSXPs).

Thanks, that was the key point I was missing. (Also mentioned to me
off list by Luke Tierney).

> See memory.c, which says, inter alia
> /* All vector objects must be a multiple of sizeof(SEXPREC_ALIGN)
>    bytes so that alignment is preserved for all objects */
> /* Node Classes.  Non-vector nodes are of class zero. Small vector
>    nodes are in classes 1, ..., NUM_SMALL_NODE_CLASSES, and large
>    vector nodes are in class LARGE_NODE_CLASS.  For vector nodes the
>    node header is followed in memory by the vector data, offset from
>    the header by SEXPREC_ALIGN. */
> And also, object.size() is only approximate, and documented to be so. In
> fact many short vectors are using larger blocks of memory incompletely, and
> of course the OS is supplying memory in pages.

Yes, the size of an object is a nebulous concept. Do you want the
marginal size or the average size? Do you want to know how big the
object is, or the impact of the object on memory allocation?


Chief Scientist, RStudio

More information about the R-devel mailing list