c++ - What is the efficient way to split a vector -
is there other constant time way split vector other using following.
std::vector<int> v_splitvector(start , end);
this take complexity of o(n). in case o(end - start). there constant time operation this.
or using wrong container task?..
the deed of "splitting" container, container vectors, elements sits on contiguous memory, require re-create / move of needs go on other side.
container list
, have elements each on own memory block can rearranged (see std::list::splice
)
but having elements in non contiguous memory may result in lower memory access performance due more frequent cache missing.
in other words, complexity of algorithm may not factor influencing performance: infrequent linear re-create may damage less frequent linear walk on dispersed elements.
the trade-off depends on how hardware manage caches , how std implementation using takes care of (and how compiler can optimize)
c++ vector
No comments:
Post a Comment