o*******0 发帖数: 699 | 1 smart pointer 实践是不是真的很有用呢?
比方说 auto_ptr, 你要把它定义在stack上,这样它才会自动消除。
可是知道把object定义在stack上,可能就不要auto_ptr了。
又比如说smart pointer with ref count. 要thread safe, 算错了还会死人。(那是
真查不出来的bug) | t****t 发帖数: 6806 | 2 auto_ptr is quite clumsy...use unique_ptr if you want unique reference.
or use shared_ptr. the point is, sometimes you don't have a clear "owner" of
the object, and you dunno who should release the object unless you track it
specifically. shared_ptr will help you do it. as for thread safe, usually i
rely on the library...
【在 o*******0 的大作中提到】 : smart pointer 实践是不是真的很有用呢? : 比方说 auto_ptr, 你要把它定义在stack上,这样它才会自动消除。 : 可是知道把object定义在stack上,可能就不要auto_ptr了。 : 又比如说smart pointer with ref count. 要thread safe, 算错了还会死人。(那是 : 真查不出来的bug)
|
|