Template Class static_allocator

Class Documentation

template<typename T>
class stream_client::stream::detail::static_allocator

A non-thread-safe static allocator.

This allocator obtains memory from a pre-allocated memory block of a given size. It does nothing in deallocate until all previously allocated blocks are deallocated, upon which it resets the internal memory block for re-use.

To use this allocator declare an instance persistent to the connection or session, and construct with the block size. A good rule of thumb is 20% more than the maximum allowed header size. For example if the application only allows up to an 8,000 byte header, the block size could be 9,600.

Then, for every instance of message construct the header with a copy of the previously declared allocator instance.

Public Types

using value_type = T
using pointer = T*
using reference = T&
using const_pointer = const T*
using const_reference = const T&
using size_type = std::size_t
using difference_type = std::ptrdiff_t

Public Functions

static_allocator() = default
inline explicit static_allocator(std::size_t size)
inline static_allocator(const static_allocator &other)
template<typename U>
inline static_allocator(const static_allocator<U> &other)
inline ~static_allocator()
inline value_type *allocate(size_type n)
inline void deallocate(value_type*, size_type)
inline void deallocate(value_type*)

Friends

template<typename U> inline friend friend bool operator== (const static_allocator &lhs, const static_allocator< U > &rhs)
template<typename U> inline friend friend bool operator!= (const static_allocator &lhs, const static_allocator< U > &rhs)