MCPcopy Create free account
hub / github.com/bytedance/sonic-cpp / MemoryPoolAllocator

Method MemoryPoolAllocator

include/sonic/allocator.h:218–240  ·  view source on GitHub ↗

Constructor with chunkSize. ! \param chunkSize The size of memory chunk. The default is kDefaultChunkSize. \param baseAllocator The allocator for allocating memory chunks. */

Source from the content-addressed store, hash-verified

216 chunks.
217 */
218 explicit MemoryPoolAllocator(
219 size_t chunkSize = SONIC_ALLOCATOR_MIN_CHUNK_CAPACITY,
220 BaseAllocator* baseAllocator = 0)
221 : cp_(chunkSize),
222 baseAllocator_(baseAllocator ? baseAllocator : new BaseAllocator()),
223 shared_(static_cast<SharedData*>(
224 baseAllocator_ ? baseAllocator_->Malloc(SIZEOF_SHARED_DATA +
225 SIZEOF_CHUNK_HEADER)
226 : 0)) {
227 sonic_assert(baseAllocator_ != 0);
228 sonic_assert(shared_ != 0);
229 if (baseAllocator) {
230 shared_->ownBaseAllocator = 0;
231 } else {
232 shared_->ownBaseAllocator = baseAllocator_;
233 }
234 shared_->chunkHead = GetChunkHead(shared_);
235 shared_->chunkHead->capacity = 0;
236 shared_->chunkHead->size = 0;
237 shared_->chunkHead->next = 0;
238 shared_->ownBuffer = true;
239 shared_->refcount = 1;
240 }
241
242 //! Constructor with user-supplied buffer.
243 /*! The user buffer will be used firstly. When it is full, memory pool

Callers

nothing calls this directly

Calls 1

MallocMethod · 0.45

Tested by

no test coverage detected