/** Default constructor. Preallocate space for items and header, then initialize header. */ CFixedSizeArrayT() { /* allocate block for header + items (don't construct items) */ m_items = (Titem*)((MallocT<int8>(ThdrSize + Tcapacity * sizeof(Titem))) + ThdrSize); SizeRef() = 0; // initial number of items RefCnt() = 1; // initial reference counter }
/** Default constructor. Preallocate space for items and header, then initialize header. */ FixedSizeArray() { /* allocate block for header + items (don't construct items) */ data = (T*)((MallocT<byte>(HeaderSize + C * Tsize)) + HeaderSize); SizeRef() = 0; // initial number of items RefCnt() = 1; // initial reference counter }
/** destroy remaining items and free the memory block */ ~CFixedSizeArrayT() { /* release one reference to the shared block */ if ((--RefCnt()) > 0) return; // and return if there is still some owner Clear(); /* free the memory block occupied by items */ free(((int8*)m_items) - ThdrSize); m_items = NULL; }
/** destroy remaining items and free the memory block */ ~FixedSizeArray() { /* release one reference to the shared block */ if ((--RefCnt()) > 0) return; // and return if there is still some owner Clear(); /* free the memory block occupied by items */ free(((byte*)data) - HeaderSize); data = NULL; }
/** Default constructor. Preallocate space for items and header, then initialize header. */ FixedSizeArray() { /* Ensure the size won't overflow. */ assert_compile(C < (SIZE_MAX - HeaderSize) / Tsize); /* allocate block for header + items (don't construct items) */ data = (T*)((MallocT<byte>(HeaderSize + C * Tsize)) + HeaderSize); SizeRef() = 0; // initial number of items RefCnt() = 1; // initial reference counter }
hsBool hsKeyedObject::MsgReceive(plMessage* msg) { plSelfDestructMsg* nuke = plSelfDestructMsg::ConvertNoRef(msg); if (nuke) { hsAssert(RefCnt() == 1, "Trying to selfdestruct with bogus refcnt"); hsRefCnt_SafeUnRef(this); return true; } return plReceiver::MsgReceive(msg); }
/** Copy constructor. Preallocate space for items and header, then initialize header. */ CFixedSizeArrayT(const CFixedSizeArrayT<Titem_, Tcapacity_>& src) { /* share block (header + items) with the source array */ m_items = src.m_items; RefCnt()++; // now we share block with the source }
/** Copy constructor. Preallocate space for items and header, then initialize header. */ FixedSizeArray(const FixedSizeArray<T, C>& src) { /* share block (header + items) with the source array */ data = src.data; RefCnt()++; // now we share block with the source }