Function set_capacity

Synopsis

#include <include/EASTL/deque.h>

void set_capacity(size_type n=base_type::npos)

Description

No description yet.

Source

Lines 1491-1512 in include/EASTL/deque.h. Line 422 in include/EASTL/deque.h.

template <typename T, typename Allocator, unsigned kDequeSubarraySize>
inline void deque<T, Allocator, kDequeSubarraySize>::set_capacity(size_type n)
{
    // Currently there isn't a way to remove all allocations from a deque, as it 
    // requires a single starting allocation for the subarrays. So we can't just
    // free all memory without leaving it in a bad state. So the best means of 
    // implementing set_capacity() is to do what we do below.
    if(n == 0)
    {
        this_type temp(mAllocator);
        DoSwap(temp);
    }
    else if(n < size())
    {
        // We currently ignore the request to reduce capacity. To do: Implement this
        // and do it in a way that doesn't result in temporarily ~doubling our memory usage.
        // That might involve trimming unused subarrays from the front or back of 
        // the container.
        resize(n);
    }        
}





Add Discussion as Guest

Log in