Class fixed_vector
Synopsis
#include <include/EASTL/fixed_vector.h>
template <typename T, size_t nodeCount, bool bEnableOverflow = true, typename OverflowAllocator = typename eastl::type_select<bEnableOverflow, EASTLAllocatorType, EASTLDummyAllocatorType>::type>
class fixed_vector : public vector<T, fixed_vector_allocator<sizeof(T), nodeCount, EASTL_ALIGN_OF(T), 0, bEnableOverflow, OverflowAllocator> >
Description
A fixed_vector with bEnableOverflow == true is identical to a regular vector in terms of its behavior. All the expectations of regular vector apply to it and no additional expectations come from it. When bEnableOverflow is false, fixed_vector behaves like regular vector with the exception that its capacity can never increase. All operations you do on such a fixed_vector which require a capacity increase will result in undefined behavior or an C++ allocation exception, depending on the configuration of EASTL.
Template parameters: T The type of object the vector holds. nodeCount The max number of objects to contain. bEnableOverflow Whether or not we should use the overflow heap if our object pool is exhausted. OverflowAllocator Overflow allocator, which is only used if bEnableOverflow == true. Defaults to the global heap.
Note: The nodeCount value must be at least 1.
Example usage: fixed_vector<Widget, 128, true> fixedVector);
fixedVector.push_back(Widget()); fixedVector.resize(200); fixedVector.clear();
Mentioned in
- Bonus / Tuple Vector Readme / How to work with tuple_vector, and where to use it
- Best Practices / Consider fixed-size containers.
- Best Practices / Use vector::reserve.
- FAQ / EASTL coverage of std STL
- FAQ / Prob.14 My stack-based fixed_vector is not respecting the object alignment requirements.
- FAQ / Debug.2 How do I view containers if the visualizer/tooltip support is not present?
- FAQ / Cont.1 Why do some containers have "fixed" versions (e.g. fixed_list) but others(e.g. deque) don't have fixed versions?
- Modules / Module List
Inheritance
Ancestors: vector
Methods
fixed_vector overload | fixed_vector | |
assign overload | ||
can_overflow | ||
clear overload | ||
DoAssign overload | ||
DoAssignFromIterator overload | ||
DoPushBack overload | This template specializes for overflow NOT enabled | |
DoPushBackMove overload | This template specializes for overflow NOT enabled | |
DoPushBackUninitialized overload | ||
full | ||
get_overflow_allocator overload | OverflowAllocator. | |
has_overflowed | ||
max_size | ||
operator= overload | ||
push_back overload | ||
push_back_uninitialized | ||
reset_lose_memory | ||
resize overload | ||
set_capacity | ||
set_overflow_allocator | ||
size | ||
swap |
Source
Lines 70-155 in include/EASTL/fixed_vector.h.
template <typename T, size_t nodeCount, bool bEnableOverflow = true, typename OverflowAllocator = typename eastl::type_select<bEnableOverflow, EASTLAllocatorType, EASTLDummyAllocatorType>::type>
class fixed_vector : public vector<T, fixed_vector_allocator<sizeof(T), nodeCount, EASTL_ALIGN_OF(T), 0, bEnableOverflow, OverflowAllocator> >
{
public:
typedef fixed_vector_allocator<sizeof(T), nodeCount, EASTL_ALIGN_OF(T),
0, bEnableOverflow, OverflowAllocator> fixed_allocator_type;
typedef OverflowAllocator overflow_allocator_type;
typedef vector<T, fixed_allocator_type> base_type;
typedef fixed_vector<T, nodeCount, bEnableOverflow, OverflowAllocator> this_type;
typedef typename base_type::size_type size_type;
typedef typename base_type::value_type value_type;
typedef typename base_type::reference reference;
typedef typename base_type::iterator iterator;
typedef typename base_type::const_iterator const_iterator;
typedef aligned_buffer<nodeCount * sizeof(T), EASTL_ALIGN_OF(T)> aligned_buffer_type;
enum { kMaxSize = nodeCount };
using base_type::get_allocator;
using base_type::mpBegin;
using base_type::mpEnd;
using base_type::internalCapacityPtr;
using base_type::resize;
using base_type::clear;
using base_type::size;
using base_type::assign;
using base_type::npos;
using base_type::DoAllocate;
using base_type::DoFree;
using base_type::DoAssign;
using base_type::DoAssignFromIterator;
protected:
aligned_buffer_type mBuffer;
public:
fixed_vector();
explicit fixed_vector(const overflow_allocator_type& overflowAllocator); // Only applicable if bEnableOverflow is true.
explicit fixed_vector(size_type n); // Currently we don't support overflowAllocator specification for other constructors, for simplicity.
fixed_vector(size_type n, const value_type& value);
fixed_vector(const this_type& x);
fixed_vector(this_type&& x);
fixed_vector(this_type&& x, const overflow_allocator_type& overflowAllocator);
fixed_vector(std::initializer_list<T> ilist, const overflow_allocator_type& overflowAllocator = EASTL_FIXED_VECTOR_DEFAULT_ALLOCATOR);
template <typename InputIterator>
fixed_vector(InputIterator first, InputIterator last);
this_type& operator=(const this_type& x);
this_type& operator=(std::initializer_list<T> ilist);
this_type& operator=(this_type&& x);
void swap(this_type& x);
void set_capacity(size_type n);
void clear(bool freeOverflow);
void reset_lose_memory(); // This is a unilateral reset to an initially empty state. No destructors are called, no deallocation occurs.
size_type max_size() const; // Returns the max fixed size, which is the user-supplied nodeCount parameter.
bool full() const; // Returns true if the fixed space has been fully allocated. Note that if overflow is enabled, the container size can be greater than nodeCount but full() could return true because the fixed space may have a recently freed slot.
bool has_overflowed() const; // Returns true if the allocations spilled over into the overflow allocator. Meaningful only if overflow is enabled.
bool can_overflow() const; // Returns the value of the bEnableOverflow template parameter.
void* push_back_uninitialized();
void push_back(const value_type& value); // We implement push_back here because we have a specialization that's
reference push_back(); // smaller for the case of overflow being disabled.
void push_back(value_type&& value);
// OverflowAllocator
const overflow_allocator_type& get_overflow_allocator() const EA_NOEXCEPT;
overflow_allocator_type& get_overflow_allocator() EA_NOEXCEPT;
void set_overflow_allocator(const overflow_allocator_type& allocator);
protected:
void* DoPushBackUninitialized(true_type);
void* DoPushBackUninitialized(false_type);
void DoPushBack(true_type, const value_type& value);
void DoPushBack(false_type, const value_type& value);
void DoPushBackMove(true_type, value_type&& value);
void DoPushBackMove(false_type, value_type&& value);
reference DoPushBack(false_type);
reference DoPushBack(true_type);
}; // fixed_vector