FastLED 3.9.15
Loading...
Searching...
No Matches

◆ ensure_size()

template<typename T, typename Allocator = fl::allocator<T>>
void fl::HeapVector< T, Allocator >::ensure_size ( fl::size n)
inline

Definition at line 431 of file vector.h.

431 {
432 if (n > mCapacity) {
433 fl::size new_capacity = (3 * mCapacity) / 2;
434 if (new_capacity < n) {
435 new_capacity = n;
436 }
437
438 T* new_array = mAlloc.allocate(new_capacity);
439
440 // Move existing elements to new array
441 for (fl::size i = 0; i < mSize; ++i) {
442 mAlloc.construct(&new_array[i], fl::move(mArray[i]));
443 }
444
445 // Clean up old array
446 if (mArray) {
447 for (fl::size i = 0; i < mSize; ++i) {
448 mAlloc.destroy(&mArray[i]);
449 }
450 mAlloc.deallocate(mArray, mCapacity);
451 }
452
455 }
456 }