Page Speed Optimization Libraries
1.13.35.1
|
#include "vector_deque.h"
Public Member Functions | |
VectorDeque () | |
void | push_back (T value) |
void | push_front (T value) |
void | pop_back () |
void | pop_front () |
T | back () const |
T | front () const |
size_t | capacity () const |
size_t | size () const |
bool | empty () const |
Static Public Member Functions | |
static size_t | initial_capacity () |
Simple implementation of deque using a vector which we double in capacity whenever we need to make room. This alternative to std::deque is perhaps a little more fragmentious to memory allocators, but will frequently allocate much less overall memory.
In particular, I found, using top, that std::deque allocates 688 bytes to construct a deque containing 4 pointers on a 64-bit system. In this implementation the cost is 64 bytes plus malloc overhead: 3 size_t integers and a pointer to an allocated array, plus the the 4 pointers in the allocated array.
This implementation lacks iterators, many std::deque methods, and the ability to work with value-semantics for the contained object. These could all be added without changing the design.
Please do not instantiate this class with an object that cannot be copied with memcpy. Pointers, integers, and floats are fine, as well as simple structs of those.
|
inline |
Constructor provides a small initial allocation, rather than constructing with zero capacity, based on expected usage patterns.