initializing std::string from char* without copy

后端 未结 6 982
南笙
南笙 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条回答
  •  自闭症患者
    2020-11-30 06:00

    Is each iteration independent enough that you can use the same std::string for each iteration? One would hope that your std::string implementation is smart enough to re-use memory if you assign a const char * to it when it was previously used for something else.

    Assigning a char * into a std::string must always at least copy the data. Memory management is one of the main reasons to use std::string, so you won't be a able to override it.

提交回复
热议问题