c++ - Is deleting an element in the middle of a std::vector still expensive with movable types? -


it thought of deleting element in middle of std::vector costly, needs copy every element after down fill hole.

with c++11, std::vector instead move elements down, should fast (if in relation copy), atleast think so. still linear in time, sure, in general should faster old version.

will true? not have worry deleting object in middle anymore?

if take account standard uses cost, costly. standard states costs in terms of operations performed on contained type, , number of operations still same, each 1 of them faster.

as example, consider in c++03 cost of inserting element in middle of vector<string>. standard calls o(n), n size of vector, actual cost o(n * m) m size of strings. reason ignoring m when analyzing cost of operations in containers depends on contained element. cost in c++0x movable type o(n) (strings can moved new positions), advertised complexity o(n) in both cases.

for simple counter-example, if consider insertion in middle of vector expensive operation in c++03, , consider std::vector<int>, insertion in middle of vector in c++0x expensive, there no speedup in case.

also note, potential improvement depend on objects being movable (which don't need be), , of current stl implementations optimized in similar way (without language support), example, dinkumware implementation (i think one) have optimizations when std::vector<std::vector<t> > grows, creates new storage , initializes empty vectors (that have no allocated memory cost minimal) , swaps vectors in old , new allocated regions, implementing move semantics.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -