/** free the blob's memory */ FORCEINLINE void Free() { if (Capacity() > 0) { RawFree(&Hdr()); InitEmpty(); } }
/** free the blob's memory */ inline void Free() { if (Capacity() > 0) { RawFree(&Hdr()); InitEmpty(); } }
/** reallocate blob data if needed */ void SmartAlloc(size_t new_size) { if (Capacity() >= new_size) return; /* calculate minimum block size we need to allocate * and ask allocation policy for some reasonable block size */ new_size = AllocPolicy(header_size + new_size + tail_reserve); /* allocate new block and setup header */ BlobHeader *tmp = RawAlloc(new_size); tmp->items = Length(); tmp->capacity = new_size - (header_size + tail_reserve); /* copy existing data */ if (tmp->items != 0) memcpy(tmp + 1, data, tmp->items); /* replace our block with new one */ if (Capacity() > 0) RawFree(&Hdr()); Init(tmp); }
/** return the number of valid data bytes in the blob */ FORCEINLINE size_t Length() const { return Hdr().items; }
/** return reference to the actual blob size - used when the size needs to be modified */ FORCEINLINE size_t& LengthRef() { return Hdr().items; }
/** return number of used items */ FORCEINLINE int Size() const { return Hdr().m_num_items; }
/** return reference to number of used items */ FORCEINLINE int& SizeRef() { return Hdr().m_num_items; }
/** return reference to the block reference counter */ FORCEINLINE int& RefCnt() { return Hdr().m_ref_cnt; }
/** return reference to number of used items */ FORCEINLINE uint& SizeRef() { return Hdr().items; }
/** return the number of valid data bytes in the blob */ inline size_t Length() const { return Hdr().items; }
/** return reference to the actual blob size - used when the size needs to be modified */ inline size_t& LengthRef() { return Hdr().items; }
/** return number of used items */ inline uint Length() const { return Hdr().items; }
/** return reference to number of used items */ inline uint& SizeRef() { return Hdr().items; }
/** return reference to the block reference counter */ inline uint& RefCnt() { return Hdr().reference_count; }
/** return number of used items */ FORCEINLINE uint Length() const { return Hdr().items; }
/** return the current blob capacity in bytes */ FORCEINLINE size_t Capacity() const { return Hdr().capacity; }
/** return the current blob capacity in bytes */ inline size_t Capacity() const { return Hdr().capacity; }
/** return reference to the block reference counter */ FORCEINLINE uint& RefCnt() { return Hdr().reference_count; }