c++ - Fastest way to add a deque onto the end of a vector? -


this question speed.

i using function in opencv libraries (in facerecognizer class) requires input of vector. need build vector combining several deque. there faster ways other iterating through deque , pushing each element vector?

some info deque: deque of 15 elements continuously push_back , if has 16+ elements pop_front. order matters.

alternatively change deque's vectors if might speed everything, understand slow when delete first element of vector when reaches size 16.

fastest way add deque onto end of vector?

getting size of deque possible in constant time (as stl containers), reserve space in vector limit memory management overhead single allocation, move elements out of deque vector:

// std::vector v, std::deque d v.reserve(v.size() + d.size()); std::move(std::begin(d), std::end(d), std::back_inserter(v)); d.clear(); // or reuse in way 

if intend append multiple containers vector, consider reserveing complete storage necessary @ once.

watch std::bad_alloc exceptions if amount of data huge. in case using contiguous storage of vector isn't ideal.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -