문제

Do I need to reserve memory when using a back:inserter?

d.reserve(s.size())
std::copy (s.begin(),s.end(),back_inserter(d));
도움이 되었습니까?

해결책

You do not need to reserve memory for the container when using std::back_inserter. However, if you know beforehand about the number of elements you are going to insert and want to prevent repeated allocations you may reserve memory.

다른 팁

You don't have to. However, if this code snippet is run very frequently, you may consider reserving memory to improve performance.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top