From simon.urbanek at r-project.org  Thu Aug 29 21:09:59 2013
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 29 Aug 2013 15:09:59 -0400
Subject: [Rd] Why does an empty vector occupy 40 bytes?
In-Reply-To: <CABdHhvGayo-GatxtrMW6oCR9a3fBbw_1gJ2Y0hvv63QMT7dDFQ@mail.gmail.com>
References: <CABdHhvFchkfQagqO1xJbEn9MbePFLO6VR4kaNhUYgzyB6Jp8tg@mail.gmail.com>
	<521F6474.40307@stats.ox.ac.uk>
	<CABdHhvHZ2RYd_TGrehUSUt5xw6y-pgNbxQ8Tpu0jiAj145Z5KQ@mail.gmail.com>
	<7447F5AA-A29E-412B-8DEF-25D6F796FF16@r-project.org>
	<CABdHhvGayo-GatxtrMW6oCR9a3fBbw_1gJ2Y0hvv63QMT7dDFQ@mail.gmail.com>
Message-ID: <B6D87831-7F8A-4474-B4A9-0021FC71B486@r-project.org>


On Aug 29, 2013, at 2:37 PM, Hadley Wickham wrote:

>> Not to be picky, but that is not the point. The alignment is due to the attrib pointer which is at offset 8 despite the fact that there is only a 4-byte element in front of it. Maybe for better illustration, this is the layout on 64-bit machines:
> 
> Ok, thanks for the clarification.
> 
>> 
>> * 4 bytes: sxpinfo header (= 32 bits)
>> * 4 bytes: --- padding so next ptr is aligned ---
>> * 8 bytes: pointer to attributes
>> * 8 bytes: pointer to next node
>> * 8 bytes: pointer to previous node
>> * 4 bytes: length
>> * 4 bytes: true length
>> 
>> = 40 bytes
>> 
>> This is already aligned so the payload alignment doesn't any extra padding so that has no effect at all.
> 
> Do pointers always have to be aligned?
> 

Depends on the architecture, e.g., Sparc doesn't allow non-aligned pointers at all (results in a segfault), SV x86_64 ABI specifies pointers to be aligned at 8 bytes, but the x86_64 CPUs will allow misaligned pointers with a performance penalty (the same was true for x86 - i.e. misaligned pointers are tolerated with a penalty).



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