C++ Smart Pointer performance

前端 未结 6 1719
北荒
北荒 2021-02-07 05:24

How much do using smart pointers, particularly boost::shared_ptr cost more compared to bare pointers in terms of time and memory? Is using bare pointers better for performance i

6条回答
  •  梦谈多话
    2021-02-07 05:56

    The only way to deal with performance problems is to profile your code. The largest part of performance problems is imagined anyway; only profiling will point out to you where your bottlenecks lie.

    If it turns out that using smart pointers produces a bottleneck where raw pointers don't, use raw pointers! Until then, I wouldn't worry too much about it; most operations on smart pointers are reasonably fast. You're likely comparing strings too often (or something like that) for them to matter.

提交回复
热议问题