initializing std::string from char* without copy

后端 未结 6 986
南笙
南笙 2020-11-30 05:41

I have a situation where I need to process large (many GB\'s) amounts of data as such:

  1. build a large string by appending many smaller (C char*) strings
6条回答
  •  猫巷女王i
    2020-11-30 06:06

    This is a lateral thinking answer, not directly addressing the question but "thinking" around it. Might be useful, might not...

    Readonly processing of std::string doesn't really require a very complex subset of std::string's features. Is there a possibility that you could do search/replace on the code that performs all the processing on std::strings so it takes some other type instead? Start with a blank class:

    class lightweight_string { };

    Then replace all std::string references with lightweight_string. Perform a compilation to find out exactly what operations are needed on lightweight_string for it to act as a drop-in replacement. Then you can make your implementation work however you want.

提交回复
热议问题