Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [compiler.services.ReferenceCountedObject<uinteger> = {
- increment = IncRefCount,
- decrement = DecRefCount,
- lifecycle = managed
- }] class RefCountedObject
- '' Construct the object and initalize the refcount to 1
- constructor(refCount as uinteger ptr)
- if (refCount = null) then
- m_refCount = new uinteger(1)
- else
- m_refCount = refCount
- IncRefCount()
- end if
- end constructor
- ''
- '' destructor should only be called when refcount reaches 0
- '' for ref counted objects I think compiler will simply call
- '' DecRefCount when out of scope. Even when explicitly
- '' delete obj ?????
- private destructor
- assert(m_refCount <> null and *m_refCount = 0)
- delete m_refCount
- m_refCount = 0
- end destructor
- '' Increment the reference count
- '' include some kind of guard to protect the operation
- sub IncRefCount
- *m_refCount += 1
- end sub
- '' decrement the reference count
- '' include some kind of guard to protect the operation
- sub DecRefCount
- *m_refCount -= 1
- ' destroy ?
- if (*m_refCount = 0) then
- delete @this
- end if
- end sub
- '' get reference count
- function GetRefCount as uinteger
- assert(m_refCount <> null)
- return *m_refCount
- end function
- '' get the reference count ptr
- function GetRefCountPtr as uinteger ptr
- return m_refCount
- end function
- '' the reference count variable
- private m_refCount as uinteger ptr
- end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement