libstdc++ leverages allocate_at_least for string and vector.
The `std::string` and `std::vector` classes in libstdc++ now use `allocate_at_least` to better utilize allocated memory, potentially improving performance with…
This commit introduces the use of allocate_at_least in std::string and std::vector within libstdc++. This function allows the containers to utilize the maximum amount of storage provided by a custom allocator, potentially improving performance and reducing memory fragmentation. The implementation relies on the known alignment behavior of standard operator new. This change primarily benefits users employing custom allocators, as it enables them to expose more information about the actual allocated storage to the containers.
In Details
This patch implements allocator<>::allocate_at_least relying on known alignment behavior of standard operator new. It then uses allocator_at_least in string and vector. This change exposes string::_S_allocate_at_least and _M_create_plus symbols to the ABI. Toolchain developers should note the changes to allocation logic within basic_string and stl_vector.
For Context
In C++, allocators manage memory allocation for containers like std::string and std::vector. The allocate_at_least function allows an allocator to inform a container about the minimum amount of memory it has allocated, which might be more than requested. This commit modifies std::string and std::vector to use this information, allowing them to potentially use more of the allocated memory, avoid unnecessary reallocations, and improve efficiency, especially when using custom memory allocators. This improvement leverages a feature defined by the C++ standard (P0401).