c++ - std::string and data alignment -
i'm planning use std::string generic data buffer (instead of roll own). need pack kinds of pod it, including user defined structs, memory buffer allocated std::string aligned such purpose ?
if it's unspecified in c++ standard, what's situation in libstdc++ ?
the host cpu x86_64.
first of all, std::string not best container use if want store arbitrary data. i'd suggest using std::vector instead.
second, alignment of allocations made container controlled allocator (the second template parameter, defaults std::allocator<t>). default allocator align allocations on size of largest standard type, long long or long double, respectively 8 , 16 bytes on machine, size of these types not mandated standard.
if want specific alignment should either check compiler aligns on, or ask alignment explicitly, supplying own allocator or using std::aligned_storage.
Comments
Post a Comment