[llvm-commits] [llvm] r47482 - /llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h
Chris Lattner
clattner at apple.com
Mon Feb 25 13:22:59 PST 2008
On Feb 22, 2008, at 9:26 AM, Anton Korobeynikov wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=47482&view=rev
> Log:
> Add smart refcounting pointer class to ADT back (known before as
> IntrusiveSPtr.h).
Hey Anton,
> +
> +#include <cassert>
> +#include <cstddef>
Out of curiosity, what needs stddef here?
> +template <class T>
> +void IntrusivePtrAddRef(llvm::RefCountedBase<T>*);
> +
> +template <class T>
> +void IntrusivePtrRelease(llvm::RefCountedBase<T>*);
> +
> +template <class T>
> +void IntrusivePtrAddRef(llvm::RefCountedBaseVPTR<T>*);
> +
> +template <class T>
> +void IntrusivePtrRelease(llvm::RefCountedBaseVPTR<T>*);
Why aren't these in the llvm namespace?
> +//
> =
> =
> =
> ----------------------------------------------------------------------=
> ==//
> +/// RefCountedBaseVPTR - A class that has the same function as
> +/// RefCountedBase, but with a virtual destructor. Should be used
> +/// instead of RefCountedBase for classes that have virtual
> +/// destructors.
>
> + template <class Derived>
> + class RefCountedBaseVPTR {
Why do you need this class? The only way a ref counted object should
be destroyable is through Release(), which should handle the case when
"Derived" itself has a virtual dtor, no?
> Classes that inherit from RefCountedBaseVPTR can't
> +/// be allocated on stack.
> +//
> =
> =
> =
> ----------------------------------------------------------------------=
> ==//
I don't think that classes inheriting from RefCountedBase should be
allocated on the stack either. release'ing them cause them to be
delete'd, which is badness for stack memory. Ref counted objects only
make sense on the heap.
> +//
> =
> =
> =
> ----------------------------------------------------------------------=
> ==//
> +/// IntrusivePtrAddRef - A utility function used by
> IntrusiveRefCntPtr
> +/// to increment the reference count of an RefCountedBase-derived
> object.
> +//
> =
> =
> =
> ----------------------------------------------------------------------=
> ==//
> +template <class T>
> +void IntrusivePtrAddRef(llvm::RefCountedBase<T>* O) {
When are these helper functions used?
Overall, this looks very useful, thanks for resurrecting it!
-Chris
More information about the llvm-commits
mailing list