Proud::RefCount< T > 클래스 템플릿 참조

Public 타입

typedef RefCount< T > Type
 

Public 멤버 함수

intptr_t GetRefCount ()
 
 RefCount (T *p=0)
 
 RefCount (const Type &other)
 
void Reset ()
 
void reset ()
 
Typeoperator= (const Type &other)
 
 operator T * () const
 
T * operator-> () const
 
T * get () const
 

상세한 설명

template<typename T>
class Proud::RefCount< T >

Smart pointer 클래스. 자세한 내용은 스마트 포인터에 있다.

RefCount를 사용시 다음을 주의해야 한다.

  • RefCount가 최초로 객체를 참조할 때 Tombstone이라는 것을 만든다. 그리고 이후의 공동 참조 객체가 등장시 이 tombstone이 공유된다. 즉 tombstone을 최초에 생성하는 시간 비용(메모리 할당 1회)이 든다.
  • 서로 다른 연관된 클래스 타입으로 캐스팅이 안된다. 예컨대 RefCount<CFile>을 RefCount<CObject>에 복사할 수 없다. 이런 경우는 RefCount의 class type으로 가급적 상위 base class를 넣고 코딩시 type cast를 매번 해야 한다.
    class Base {};
    class A:public Base {};
    void Foo()
    {
    RefCount<A> a;
    RefCount<Base> b;
    a = b; // 에러
    }
    void Foo2()
    {
    RefCount<Base> a;
    RefCount<Base> b(new A);
    a = b; // OK
    A* p = (A*)a.get(); // 타입 A를 참조하려면 이렇게 해야 한다.
    }
매개변수
T스마트 포인터가 다룰 객체의 타입
AllocTAllocType 값 중 하나.
IsThreadSafe<안씀!> true이면 이 스마트 포인터 변수를 여러 스레드가 동시에 다루어도 안전하다. 그러나 성능 저하가 있다.

생성자 & 소멸자 문서화

template<typename T>
Proud::RefCount< T >::RefCount ( T *  p = 0)
inlineexplicit

생성자. 포인터 p가 가리키는 객체의 소유권을 가져온다.

template<typename T>
Proud::RefCount< T >::RefCount ( const Type other)
inline

복사 대입 연산자

멤버 함수 문서화

template<typename T>
intptr_t Proud::RefCount< T >::GetRefCount ( )
inline

이 객체를 참조하고 있는 다른 변수 객체들의 갯수를 리턴한다. 즉 참조 횟수다.