c++ - Can you prevent std::vector bounds-checking on push_back()? -
i know there ways either or not bounds-checking when indexing vector, on push_back(), if know capacity of vector large enough (ie., reserved enough), , ran loop pushing elements it, i'd assume since it's dynamically resizing have bounds-checking (or size checking) on every push_back.
if case, thinking fast_push() useful if can know won't exceed capacity.
i've heard claims of vector libraries being faster, such 1 http://andreoffringa.org/?q=uvector , didn't see issue of push_back() when knowing bounds checking won't needed. 1 in link makes claims of 50% speed improvements. 1 of them being preventing value initialisation on construction when don't need it, , other things.
thanks.
since c++11 there addition std::vector::emplace_back(...). function construct element in place , may yield performance boost.
and should not not worry range checking in std::vector. 1 instruction , branch prediction be right, if vector big enough.
Comments
Post a Comment