[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: garbage collection thoughts... again?!
- From: Thatcher Ulrich <tu@...>
- Date: Thu, 29 May 2003 20:49:30 -0400 (EDT)
On Thu, 29 May 2003, Mark Hamburg wrote:
> on 5/29/03 10:07 AM, Thatcher Ulrich at tu@tulrich.com wrote:
>
> > void SomeFunction(const SPtr<SomeObject>& ptr)
> > {
> > // ptr is a reference to an already-existing SPtr<>, so there's
> > // no ref inc/dec overhead in the function call binding.
> > }
> >
> > This is safe and easy, in my experience. In any case, most
> > incremental collectors will need a write-barrier, which in practice is
> > probably worse than inc/dec of a ref count.
>
> That's what we did on the last project I worked on as well. It's safe from
> the standpoint that you won't get stuck with a stale pointer, but it doesn't
> have quite the same semantics since the pointer can be changed and that
> change will be visible in the called code. "const" just means that
> SomeFunction can't change the pointer.
True; the above example is the smart-pointered equivalent of
"SomeFunction(SomeObject* ptr)". At work we use a "SPtrC<>" for const
pointers, if you want to emulate "SomeFunction(const SomeObject*
ptr)".
One of the nice things about C++ is that this ref-counted SPtr<> junk
can be made pretty automatic.
-Thatcher