One thing I’ve always wondered about is if the instances of std::string that I use in my C++ code use the same allocator or do they have their own separate memory pools?
Obviously sharing a single memory pool across multiple, frequently created and destroyed strings is more efficient. Can anyone confirm or deny this for me please?
By default, they all use
std::allocator, which uses standard memory routines to get free heap blocks. There is no pooling involved on this layer.(However, most heap implementations use a dedicated low-fragmentation heap to serve small allocations, and strings are most likely to fall into this category. But this is implementation dependent and not exclusive to or optimized for
std::strings …).