From h.wickham at gmail.com  Thu Aug 29 15:39:46 2013
From: h.wickham at gmail.com (Hadley Wickham)
Date: Thu, 29 Aug 2013 08:39:46 -0500
Subject: [Rd] Why does an empty vector occupy 40 bytes?
Message-ID: <CABdHhvFchkfQagqO1xJbEn9MbePFLO6VR4kaNhUYgzyB6Jp8tg@mail.gmail.com>

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?

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/



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