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

Method Malloc

include/sonic/allocator.h:366–380  ·  view source on GitHub ↗

Allocates a memory block. (concept Allocator)

Source from the content-addressed store, hash-verified

364
365 //! Allocates a memory block. (concept Allocator)
366 void* Malloc(size_t size) {
367 sonic_assert(shared_->refcount > 0);
368 if (!size) return NULL;
369
370 size = SONIC_ALIGN(size);
371 LOCK_GUARD;
372 if (sonic_unlikely(shared_->chunkHead->size + size >
373 shared_->chunkHead->capacity)) {
374 if (!AddChunk(cp_.ChunkSize(size))) return NULL;
375 }
376
377 void* buffer = GetChunkBuffer(shared_) + shared_->chunkHead->size;
378 shared_->chunkHead->size += size;
379 return buffer;
380 }
381
382 //! Resizes a memory block (concept Allocator)
383 void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) {

Callers

nothing calls this directly

Calls 1

ChunkSizeMethod · 0.45

Tested by

no test coverage detected