Marcel Mueller
2024-03-09 10:09:12 UTC
Is it reasonable to return small strings a std::array to avoid copying?
std::string might require allocation if it has no small string
optimization build in. Furthermore it cannot be initialized from old C
style APIs that require char* buffer and size_t buffer_size.
The idea is to return std::array<char,10> or something like that. This
causes no allocation and the compiler should be able to optimize the
return value to emplace the result into the callers storage.
Any other idea?
Marcel
std::string might require allocation if it has no small string
optimization build in. Furthermore it cannot be initialized from old C
style APIs that require char* buffer and size_t buffer_size.
The idea is to return std::array<char,10> or something like that. This
causes no allocation and the compiler should be able to optimize the
return value to emplace the result into the callers storage.
Any other idea?
Marcel