The cost of passing by shared_ptr

前端 未结 5 1367
迷失自我
迷失自我 2020-12-07 09:35

I use std::tr1::shared_ptr extensively throughout my application. This includes passing objects in as function arguments. Consider the following:

class Datas         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 10:22

    You need shared_ptr only to pass it to functions/objects which keep it for future use. For example, some class may keep shared_ptr for using in an worker thread. For simple synchronous calls it's quite enough to use plain pointer or reference. shared_ptr should not replace using plain pointers completely.

提交回复
热议问题