]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
osd/OSDMap: using std::vector::reserve to reduce memory reallocation
authorxie xingguo <xie.xingguo@zte.com.cn>
Mon, 18 Feb 2019 07:40:22 +0000 (15:40 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Mon, 18 Feb 2019 07:40:22 +0000 (15:40 +0800)
commit4a0eabb3a65107cbee5e692ade564102e2b2f8aa
treed3e58fb588ebd9c718fb5e757cf310235a7d5e4a
parente36364b1603e438672ebcc122cf260ee313fd1c9
osd/OSDMap: using std::vector::reserve to reduce memory reallocation

In C++ vectors are dynamic arrays.
Vectors are assigned memory in blocks of contiguous locations.
When the memory allocated for the vector falls short of storing
new elements, a new memory block is allocated to vector and all
elements are copied from the old location to the new location.
This reallocation of elements helps vectors to grow when required.
However, it is a costly operation and time complexity is involved
in this step is linear.
Try to use std::vector::reserve whenever possible if performance
matters.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/osd/OSDMap.cc