Allocates a memory block. (concept Allocator)
| 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) { |