]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.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>
Wed, 20 Feb 2019 07:25:25 +0000 (15:25 +0800)
commit0729a78877eef994d595ba0f411919025ec0b3a4
tree140709037587ac0ca1fb7c3582da58fe078676e5
parentf4f66e4f0af96e6e4daf86b81ec479f5fc8a3fd8
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>
(cherry picked from commit 4a0eabb3a65107cbee5e692ade564102e2b2f8aa)
src/osd/OSDMap.cc