某處我看到一篇關於創建boost shared_ptr的優化方式的帖子,以便它同時分配ptr管道和pointee。我做了SO搜索,但有很多職位shared_ptr,我無法找到它。請有人聰明請轉貼shared_ptr分配優化
編輯: 感謝您的回答。額外的信用問題。什麼是返回null shared_ptr的正確(首選?)成語?即
FooPtr Func()
{
if(some_bad_thing)
return xxx; // null
}
我
return FooPtr((Foo*)0);
看起來有點klunky
我會使用默認ctor作爲shared_ptr,或者調用沒有參數的make_shared。 – 2010-09-24 23:27:23