Vault  4.1
Public Member Functions | Friends
VCompactingDeque< _Tp, _Alloc > Class Template Reference

VCompactingDeque is a template class that subclasses std::deque and adds the ability to "compact" the deque internal structures when the deque drains. More...

#include <vcompactingdeque.h>

Inherits std::deque< T >.

List of all members.

Public Member Functions

 VCompactingDeque (size_t highWaterMarkRequired=64, size_t lowWaterMarkRequired=0)
 Constructs the deque with optional specified thresholds.
void pop_front ()
 Removes the first element from the queue, possibly triggering a compaction afterward.
void pop_back ()
 Removes the last element from the queue, possibly triggering a compaction afterward.
void compact ()
 Performs compaction of the deque bookkeeping overhead.

Friends

class VMessageUnit

Detailed Description

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
class VCompactingDeque< _Tp, _Alloc >

VCompactingDeque is a template class that subclasses std::deque and adds the ability to "compact" the deque internal structures when the deque drains.

Otherwise, with a standard deque, you can have an apparent memory leak when the queue drains but holds onto lots of internal bookkeeping memory. You can specify in the constructor what thresholds trigger the compaction. Compaction only can happen when you call pop_front() or pop_back() (the methods that may shrink the queue) and do so via a reference or pointer to this subclass. Compaction does not occur on erase() because the returned iterator would be invalid or have to be recalculated.

Definition at line 26 of file vcompactingdeque.h.


Constructor & Destructor Documentation

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
VCompactingDeque< _Tp, _Alloc >::VCompactingDeque ( size_t  highWaterMarkRequired = 64,
size_t  lowWaterMarkRequired = 0 
) [inline]

Constructs the deque with optional specified thresholds.

Parameters:
highWaterMarkRequiredcompaction occurs only after the queue has grown to this size, and later is drained down to the lowWaterMarkRequired
lowWaterMarkRequiredcompaction occurs only after the highWaterMarkRequired was previously reached, and the queue then drains down to this size

Definition at line 36 of file vcompactingdeque.h.


Member Function Documentation

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void VCompactingDeque< _Tp, _Alloc >::pop_front ( ) [inline]

Removes the first element from the queue, possibly triggering a compaction afterward.

You will have already called front() to get that element beforehand if you want it. Note that because STL templates do not use virtual methods, this override will not be called should you access this deque via a base class reference or pointer.

Definition at line 50 of file vcompactingdeque.h.

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void VCompactingDeque< _Tp, _Alloc >::pop_back ( ) [inline]

Removes the last element from the queue, possibly triggering a compaction afterward.

You will have already called back() to get that element beforehand if you want it. Note that because STL templates do not use virtual methods, this override will not be called should you access this deque via a base class reference or pointer.

Definition at line 64 of file vcompactingdeque.h.

template<typename _Tp, typename _Alloc = std::allocator<_Tp>>
void VCompactingDeque< _Tp, _Alloc >::compact ( ) [inline]

Performs compaction of the deque bookkeeping overhead.

You can manually direct a compaction by calling this method. Not necessary if you always use the defined pop_front() and pop_back() functions, because they do this automatically when the high/low water mark thresholds are reached.

Definition at line 78 of file vcompactingdeque.h.


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

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.