나는 vC++ 2013 익스프레스 에디션을 사용하고 있습니다. std :: async와 std :: future 같은 C++ 11의 새로운 기능을 연구 중입니다.표준 가속화 : 새로운 C++ 11 std :: async 채우기 .vector
나는 Foo 클래스가 있으며 std::shared_ptr<std::vector<unsigned int> >
입니다. Foo ctor에서 std :: make_shared를 사용하여 힙에 벡터를 할당합니다. foo.cpp의에서 Foo.h
Class Foo{
public:
Foo();
private:
std::shared_ptr<std::vector<unsigned int> > testVector;
unsigned int MAX_ITERATIONS = 800000000;
void fooFunction();
}
에서
는
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);
}
}
목 문제는 내가 표준 : 비동기 호출 (표준 : : 출시 :: 비동기 사이에 어떤 이득을 볼 수있다 , & Foo :: fooFunction, this) .get(); 및 fooFunction();
왜 ?? 도움이 될 것입니다. 감사합니다.
시간이 다른 이유는 무엇입니까? 어쨌든 코드가 효과적으로 직렬화됩니다. – zch