libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs > Class Template Reference

A very simple custom allocator that allocates a contiguous block of uninitialised items on the stack. More...

#include <memory_buffer.hpp>

Public Types

enum  : std::size_t { stride =sizeof(element_type) , max_size_ =num_objs }
 
typedef El element_type
 The type of items to allocate, but not initialise. More...
 
typedef std::size_t size_type
 
typedef unsigned char const * const_iterator
 
typedef unsigned char * iterator
 

Public Member Functions

 BOOST_MPL_ASSERT ((boost::mpl::greater< boost::mpl::int_< num_objs >, boost::mpl::int_< 0 >>))
 
 BOOST_MPL_ASSERT ((boost::mpl::greater< boost::mpl::int_< stride >, boost::mpl::int_< 0 >>))
 
 BOOST_MPL_ASSERT ((boost::mpl::greater< boost::mpl::int_< max_size_ >, boost::mpl::int_< 0 >>))
 
 memory_buffer () noexcept(true) FORCE_INLINE
 
 ~memory_buffer () noexcept(true) FORCE_INLINE
 
const_iterator data () const noexcept(true) FORCE_INLINE
 
iterator data () noexcept(true) FORCE_INLINE
 

Static Public Member Functions

static constexpr size_type max_size () noexcept(true) FORCE_INLINE
 

Friends

tostreamoperator<< (tostream &os, memory_buffer const &t) noexcept(false)
 

Detailed Description

template<class El, std::size_t num_objs>
class jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >

A very simple custom allocator that allocates a contiguous block of uninitialised items on the stack.

A simple char[] does not respect alignment, whereas this class ensures that the objects are suitably aligned. Note that the items allocated are guaranteed not to be initialised, which is how this differs from std::array, which, as I understand it, must default-initialise each std::array::value_type member according to 8.5.1p7 of the ISO Standard.

See also
std::array

Definition at line 141 of file memory_buffer.hpp.

Member Typedef Documentation

◆ const_iterator

template<class El , std::size_t num_objs>
typedef unsigned char const* jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::const_iterator

Definition at line 161 of file memory_buffer.hpp.

◆ element_type

template<class El , std::size_t num_objs>
typedef El jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::element_type

The type of items to allocate, but not initialise.

Definition at line 143 of file memory_buffer.hpp.

◆ iterator

template<class El , std::size_t num_objs>
typedef unsigned char* jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::iterator

Definition at line 162 of file memory_buffer.hpp.

◆ size_type

template<class El , std::size_t num_objs>
typedef std::size_t jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::size_type

Definition at line 160 of file memory_buffer.hpp.

Member Enumeration Documentation

◆ anonymous enum

template<class El , std::size_t num_objs>
anonymous enum : std::size_t
Enumerator
stride 

The sizeof(element_type) each item, specifically in bytes.

max_size_ 

The size of the buffer in number of items.

Definition at line 150 of file memory_buffer.hpp.

Constructor & Destructor Documentation

◆ memory_buffer()

template<class El , std::size_t num_objs>
jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::memory_buffer ( )
inlinenoexcept

Definition at line 164 of file memory_buffer.hpp.

◆ ~memory_buffer()

template<class El , std::size_t num_objs>
jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::~memory_buffer ( )
inlinenoexcept

Definition at line 167 of file memory_buffer.hpp.

Member Function Documentation

◆ BOOST_MPL_ASSERT() [1/3]

template<class El , std::size_t num_objs>
jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::BOOST_MPL_ASSERT ( (boost::mpl::greater< boost::mpl::int_< max_size_ >, boost::mpl::int_< 0 >>)  )

◆ BOOST_MPL_ASSERT() [2/3]

template<class El , std::size_t num_objs>
jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::BOOST_MPL_ASSERT ( (boost::mpl::greater< boost::mpl::int_< num_objs >, boost::mpl::int_< 0 >>)  )

◆ BOOST_MPL_ASSERT() [3/3]

template<class El , std::size_t num_objs>
jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::BOOST_MPL_ASSERT ( (boost::mpl::greater< boost::mpl::int_< stride >, boost::mpl::int_< 0 >>)  )

◆ data() [1/2]

template<class El , std::size_t num_objs>
const_iterator jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::data ( ) const
inlinenoexcept

Definition at line 169 of file memory_buffer.hpp.

◆ data() [2/2]

template<class El , std::size_t num_objs>
iterator jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::data ( )
inlinenoexcept

Definition at line 172 of file memory_buffer.hpp.

◆ max_size()

template<class El , std::size_t num_objs>
static constexpr size_type jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::max_size ( )
inlinestaticconstexprnoexcept
Returns
The size of the buffer in number of items.

Definition at line 179 of file memory_buffer.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::stack::memory_buffer< El, num_objs >::max_size_.

Friends And Related Function Documentation

◆ operator<<

template<class El , std::size_t num_objs>
tostream& operator<< ( tostream os,
memory_buffer< El, num_objs > const &  t 
)
friend
Todo:
Implement using the advice given in "Standard C++ IOStreams and Locales" by A.Langer & K.Kreft, page 170.

Definition at line 186 of file memory_buffer.hpp.


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