lundi 21 mai 2018

What is the reasoning behind libc++'s alignment patterns for std::basic_string?

While looking at the libc++ implementation of std::basic_string, I came across this in line 1374 (at the time of writing):

enum {__alignment = 16};

This value is used in subsequent alignment calculations, string size requests being rounded up to multiples of this number.

I can accept that some rounding is going on to avoid memory fragmentation or whatever, but...

I wonder if there is any specific rationale behind using a hardcoded 16 as the number here, or if it's just used as a "nice 'round' number".

For a 64-bit machine, 16 amounts to alignof( std::max_align_t ), and that makes some sort of sense. But the exact same value for __alignment is used for 32-bit architectures as well, so...?

Aucun commentaire:

Enregistrer un commentaire