How to programatically find if a std::wstring
is allocated with Short String Optimization
? I was trying to detect such cases and use reserve
to move out of the SSO.
The below code prints a small difference in the addresses:
#include <string>
#include <iostream>
int main ()
{
std::wstring str = L"H";
std::cout<<&str<<" "<<(void*)str.data()<<"\n";
}
Output example:
0x7ffc39465220 0x7ffc39465230
Aucun commentaire:
Enregistrer un commentaire