1
我使用vC++ 2013快速版。 我正在研究C++ 11的一些新功能,如std :: async和std :: future。加速std:.vector填充新的C++ 11 std :: async
我有一個類Foo,std::shared_ptr<std::vector<unsigned int> >
。 在Foo ctor我使用std :: make_shared在堆中分配向量;
從foo.h中
Class Foo{
public:
Foo();
private:
std::shared_ptr<std::vector<unsigned int> > testVector;
unsigned int MAX_ITERATIONS = 800000000;
void fooFunction();
}
從Foo.cpp中
Foo::Foo(){
testVector = std::make_shared<std::vector<unsigned int> >();
//fooFunction(); this take about 20 sec
std::async(std::launch::async, &Foo::fooFunction, this).get(); // and this about the same!!
}
void Foo:fooFunction(){
for (unsigned int i = 0; i < MAX_ITERATIONS; i++){
testVector->push_back(i);
}
}
釷的問題是我不能看到調用的std ::異步(STD ::推出::異步之間的任何增益,& Foo :: fooFunction,this).get();和fooFunction();
爲什麼? 任何幫助將不勝感激。 致以問候
你爲什麼期望時代會不同?無論如何,你的代碼是有效的序列化。 – zch