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::string
s ...).
different instances of c++ use the same allocator if you don't specify one. You perhaps are referring to string interning that is standard in java/python etc. If so, no. There is no 'standard' facility for that. However it is easy to add if frequent create/destroy is an issue
http://en.wikipedia.org/wiki/String_interning
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With