I've identified the bottleneck in my program as the copy operation from intaking a char[] and initializing a string from it, thus copying the buffer.
const std::wstring name = payload->Header->Name;
This code happens over and over again with different values, but for the lifetime of name
, the payload struct cannot change. So there is only need for a single buffer to exist. The wchar array comes from an API that cannot change. And there is subsequent code that expects name
to be a wstring and is well optimized already and I consider it cleaner that it uses wstring and not arrays.
I know under the hood, wstring is just a wchar buffer anyway. What I need is like the general equivalent of std::move but for this special case. Is there no standard way to even signify the intent here, so the compiler could maybe optimize this if it can?
Aucun commentaire:
Enregistrer un commentaire