/** 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 }
/** Clear (destroy) all items */ FORCEINLINE void Clear() { /* walk through all allocated items backward and destroy them */ for (Titem *pItem = &m_items[Size() - 1]; pItem >= m_items; pItem--) { pItem->~Titem_(); } /* number of items become zero */ SizeRef() = 0; }
/** 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 }
/** Clear (destroy) all items */ inline void Clear() { /* Walk through all allocated items backward and destroy them * Note: this->Length() can be zero. In that case data[this->Length() - 1] is evaluated unsigned * on some compilers with some architectures. (e.g. gcc with x86) */ for (T *pItem = this->data + this->Length() - 1; pItem >= this->data; pItem--) { pItem->~T(); } /* number of items become zero */ SizeRef() = 0; }
/** add (allocate), but don't construct item */ FORCEINLINE Titem& AddNC() { assert(!IsFull()); return m_items[SizeRef()++]; }
/** add (allocate), but don't construct item */ inline T *Append() { assert(!IsFull()); return &data[SizeRef()++]; }
/** add (allocate), but don't construct item */ FORCEINLINE T *Append() { assert(!IsFull()); return &data[SizeRef()++]; }