|
Boost : |
From: Darin Adler (darin_at_[hidden])
Date: 2001-11-01 19:27:58
on 11/1/01 4:00 PM, Zhang, Gary at Gary.Zhang_at_[hidden] wrote:
> Can somebody tell me why the reference count is incremented
> when shared_ptr is initialized by a null ( 0 ) pointer ?
Adding a special case for the null pointer would have little benefit, and a
non-negligible cost.
Maintaining a reference count of 0 for null pointers would require
additional code in all four of the constructors, the auto_ptr assignment
operator, the reset function, the dispose function, and the share function.
> Isn't it more logical for ref_count to remain 0 since
> NULL pointer has no sharing value ?
I'm not sure that it is. Can you give an example of some code where this
would make a difference to help me understand the advantage of having a
special case for the null pointer? I presume you're using either the
unique() or use_count() function.
My guess is that if we find that it's important for null pointers to return
a value from use_count() or unique() different from what they currently
return, it will be best to add the check for null to those functions.
-- Darin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk