From simon.urbanek at r-project.org  Thu Aug 29 16:59:09 2013
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 29 Aug 2013 10:59:09 -0400
Subject: [Rd] Why does an empty vector occupy 40 bytes?
In-Reply-To: <CABdHhvFchkfQagqO1xJbEn9MbePFLO6VR4kaNhUYgzyB6Jp8tg@mail.gmail.com>
References: <CABdHhvFchkfQagqO1xJbEn9MbePFLO6VR4kaNhUYgzyB6Jp8tg@mail.gmail.com>
Message-ID: <90CCA572-7E85-49FD-8013-EC936C5CBA7C@r-project.org>


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



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