Cogs.Core
SmallVector.cpp
1#include "SmallVector.h"
2
3void Cogs::Collections::SmallVectorBase::growPod(const void* firstElement, const size_t minSizeBytes)
4{
5 size_t newCapacity = capacityInBytes() * 2;
6 if (minSizeBytes > newCapacity) newCapacity = minSizeBytes;
7
8 const size_t currentSize = sizeInBytes();
9
10 void * newPtr;
11 if (firstPtr == firstElement) {
12 newPtr = allocator->allocate(newCapacity);
13
14 std::memcpy(newPtr, firstPtr, currentSize);
15 } else {
16 newPtr = allocator->allocate(newCapacity);
17
18 std::memcpy(newPtr, firstPtr, currentSize);
19
20 allocator->deallocate(firstPtr, capacityInBytes());
21 }
22
23 firstPtr = newPtr;
24 lastPtr = static_cast<uint8_t*>(firstPtr) + currentSize;
25 capacityPtr = static_cast<uint8_t*>(firstPtr) + newCapacity;
26}
virtual void deallocate(void *ptr, size_t size, MemBlockType type=MemBlockType::Block)
Deallocate the memory block at the given pointer, with the given size.
Definition: Allocator.cpp:58
virtual void * allocate(size_t size, size_t alignment=0, MemBlockType type=MemBlockType::Block)
Allocate raw memory.
Definition: Allocator.cpp:29