Creates a new chunk. ! \param capacity Capacity of the chunk in bytes. \return true if success. */
| 435 | \return true if success. |
| 436 | */ |
| 437 | bool AddChunk(size_t capacity) { |
| 438 | if (!baseAllocator_) { |
| 439 | shared_->ownBaseAllocator = baseAllocator_ = new BaseAllocator(); |
| 440 | } |
| 441 | if (ChunkHeader* chunk = static_cast<ChunkHeader*>( |
| 442 | baseAllocator_->Malloc(SIZEOF_CHUNK_HEADER + capacity))) { |
| 443 | chunk->capacity = capacity; |
| 444 | chunk->size = 0; |
| 445 | chunk->next = shared_->chunkHead; |
| 446 | shared_->chunkHead = chunk; |
| 447 | return true; |
| 448 | } |
| 449 | return false; |
| 450 | } |
| 451 | |
| 452 | static inline void* AlignBuffer(void* buf, size_t& size) { |
| 453 | sonic_assert(buf != 0); |