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

Simon Urbanek simon.urbanek at r-project.org
Thu Aug 29 16:59:09 CEST 2013


On Aug 29, 2013, at 9:39 AM, Hadley Wickham wrote:

> Hi all,
> 
> Why is the object size of an empty vector 40 bytes? (At least in 64-bit R.)
> 
> object.size(integer(0))
> # 40 bytes
> 
> Reading R internals, it looks like it should be:
> 
> * 4 bytes: sxpinfo header (= 32 bits)
> * 8 bytes: pointer to attributes
> * 8 bytes: pointer to next node
> * 8 bytes: pointer to previous node
> * 4 bytes: length
> * 4 bytes: true length
> 
> = 36 bytes
> 
> Where are the extra 4 bytes coming from? What have I missed?
> 

Alignment of pointers -- there are 4 bytes of padding on 64-bit machines after sxpinfo


> I thought it might be for memory alignment, but if it was padded by an
> additional 4 bytes, then an integer vector of length 1 should be the
> same size, assuming I've interpreted the comment about "aligned as
> required" correctly.
> 
> Thanks!
> 
> Hadley
> 
> -- 
> Chief Scientist, RStudio
> http://had.co.nz/
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 



More information about the R-devel mailing list