Allocate more memory
| 60 | |
| 61 | /// Allocate more memory |
| 62 | void allocate(uint64 capacity) { |
| 63 | |
| 64 | // Make sure capacity is an integral multiple of alignment |
| 65 | capacity = std::ceil(capacity / float(GLOBAL_ALIGNMENT)) * GLOBAL_ALIGNMENT; |
| 66 | |
| 67 | T* newArray = static_cast<T*>(mAllocator.allocate(capacity * sizeof(T))); |
| 68 | assert(newArray != nullptr); |
| 69 | |
| 70 | // If there |
| 71 | if (mCapacity > 0) { |
| 72 | |
| 73 | if (mNbElements > 0) { |
| 74 | |
| 75 | // Copy the previous items in the new array |
| 76 | std::uninitialized_copy(mArray, mArray + mNbElements, newArray); |
| 77 | } |
| 78 | |
| 79 | // Release memory of the previous array |
| 80 | mAllocator.release(mArray, mCapacity * sizeof(T)); |
| 81 | } |
| 82 | |
| 83 | mArray = newArray; |
| 84 | |
| 85 | mCapacity = capacity; |
| 86 | } |
| 87 | |
| 88 | public: |
| 89 |