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 ( size_t n)
inline

Definition at line 373 of file vector.h.

373 {
374 if (n > mCapacity) {
375 size_t new_capacity = (3 * mCapacity) / 2;
376 if (new_capacity < n) {
377 new_capacity = n;
378 }
379
380 T* new_array = mAlloc.allocate(new_capacity);
381
382 // Copy existing elements to new array
383 for (size_t i = 0; i < mSize; ++i) {
384 mAlloc.construct(&new_array[i], mArray[i]);
385 }
386
387 // Clean up old array
388 if (mArray) {
389 for (size_t i = 0; i < mSize; ++i) {
390 mAlloc.destroy(&mArray[i]);
391 }
392 mAlloc.deallocate(mArray, mCapacity);
393 }
394
397 }
398 }

Referenced by fl::HeapVector< DrawItem >::push_back(), fl::HeapVector< DrawItem >::reserve(), and fl::HeapVector< DrawItem >::resize().

+ Here is the caller graph for this function: