简体   繁体   English

什么是std :: vector :: _ emplace_back_slow_path / std :: vector :: _ push_back_slow_path?

[英]What is std::vector::_emplace_back_slow_path / std::vector::_push_back_slow_path?

When using a call profiler, I noticed a high runtime cost and a high number of allocations in std::vector::_emplace_back_slow_path . 使用呼叫探查器时,我注意到std::vector::_emplace_back_slow_path运行时成本很高并且分配数量std::vector::_emplace_back_slow_path Because I am concerned about performance, I want this to say "fast path". 因为我担心性能,所以我想这样说“快速路径”。 What am I doing wrong? 我究竟做错了什么?

Looking at the implementation , the "slow path" is the path taken if a reallocation is needed: 查看实现 ,“慢速路径”是需要重新分配时采用的路径:

vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
{
    if (this->__end_ < this->__end_cap())
    {
        // This is the code that you could call the "fast path"
    }
    else
        __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
}

This also applies to std::vector::_push_back_slow_path . 这也适用于std::vector::_push_back_slow_path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM