[libcxx-commits] [libcxx] Lower std::string's alignment requirement from 16 to 8. (PR #68749)
Martijn Vels via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 10 16:18:34 PDT 2023
================
@@ -1851,7 +1851,14 @@ private:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
size_type __align_it(size_type __s) _NOEXCEPT
{return (__s + (__a-1)) & ~(__a-1);}
- enum {__alignment = 16};
+ enum {
+ __alignment =
+#ifdef _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
+ 8
+#else
+ 16
----------------
martijnvels wrote:
My suspicion is that someone figured 'malloc() always returns 16 byte aligned data' and likewise, "it is likely then also aligned in multiples of 16", which doesn't hold true. (in practice glib malloc is n * 16 + 8 for small allocations as it uses 8 bytes overhead).
That's just my guess, there is no need for any 16 byte alignment obviously in string, so it must have been some attempt to align better to the (default) allocator. (obviously this is different with tcmalloc, jemalloc, etc)
https://github.com/llvm/llvm-project/pull/68749
More information about the libcxx-commits
mailing list