8 questions
-2
votes
1
answer
184
views
Implementation of std::string class members [duplicate]
class string {
struct long_mode {
size_t size;
size_t capacity;
char* buffer;
};
struct short_mode {
uint8_t size;
char buffer[23];
};
...
4
votes
2
answers
525
views
Check if a `std::string` uses small string optimization (SSO)
I want to check if a std::string value is using the small string optimization (SSO).
I am wondering if this is defined behavior:
#include <string>
#include <cstdint>
auto is_sso(const std:...
22
votes
2
answers
8k
views
No small string optimization with gcc?
Most std::string implementations (GCC included) use small string optimization. E.g. there's an answer discussing this.
Today, I decided to check at what point a string in a code I compile gets moved ...
11
votes
1
answer
1k
views
Does FBString's small string optimization rely on undefined behavior?
Facebook's fbstring_core class uses the "Small String Optimization" described in this talk wherein the storage for the class' data members -- a Char*, size and capacity -- will be repurposed to store ...
1
vote
2
answers
298
views
Reliably using C++ Small String Optimization to fread short std::strings from Files into Memory
I have the following class, it contains a data structure called Index, which is expensive to compute.
So I am caching the index to disk and reading it in again. The index element id of template type T ...
10
votes
1
answer
2k
views
C++11 and C++03 differs in support for small string optimization for std::string?
In the compatibility appendix of the C++11 standard, one of the change from C++03 to C++11 is described as below:
C.2.11 Clause 21: strings library
21.4.1
Change: Loosen basic_string ...
11
votes
1
answer
1k
views
std::string — small string optimization and swap
From N3290, [container.requirements.general]:
The expression a.swap(b), for containers a and b of a standard container type other than array, shall exchange the values of a and b without invoking ...
35
votes
4
answers
17k
views
small string optimization for vector?
I know several (all?) STL implementations implement a "small string" optimization where instead of storing the usual 3 pointers for begin, end and capacity a string will store the actual character ...