Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
net_instaweb::VectorDeque< T > Class Template Reference

#include "vector_deque.h"

Public Member Functions

 VectorDeque ()
 
void push_back (T value)
 
void push_front (T value)
 
void pop_back ()
 
void pop_front ()
 
back () const
 
front () const
 
size_t capacity () const
 
size_t size () const
 
bool empty () const
 

Static Public Member Functions

static size_t initial_capacity ()
 

Detailed Description

template<class T>
class net_instaweb::VectorDeque< T >

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.

Constructor & Destructor Documentation

template<class T>
net_instaweb::VectorDeque< T >::VectorDeque ( )
inline

Constructor provides a small initial allocation, rather than constructing with zero capacity, based on expected usage patterns.


The documentation for this class was generated from the following file: