C++中std::string是日常Coding中经常使用的一个类,使用起来非常方便,但是也存在一些弊端。
如下代码,参数传递的过程发生了内存分配(Memory Allocation)和内存拷贝。
void fun(const std::string& s) {
std::cout << s << std::endl;
}
const char* ch = "hello world";
// bad way, expensive if the string is l
C++11中的std::future是一个模板类。std::future提供了一种用于访问异步操作结果的机制。std::future所引用的共享状态不能与任何其它异步返回的对象共享(与std::shared_future相反)( std::future references shared state that is not shared with any other asynchronous return objects (as opposed to std::shared_future))。一