2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 // Stefan Bund <g0dil@berlios.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief pool_alloc_mixin public header */
24 #ifndef HH_pool_alloc_mixin_
25 #define HH_pool_alloc_mixin_ 1
28 #include <boost/pool/singleton_pool.hpp>
30 //#include "pool_alloc_mixin.mpp"
31 ///////////////////////////////hh.p////////////////////////////////////////
35 struct pool_alloc_mixin_tag;
37 /** \brief Mixin to assign pool allocator to a class
39 This mixin will overload a classes <tt>operator new</tt> and <tt>operator delete</tt> so as
40 to make the class use the <a
41 href="http://www.boost.org/libs/pool/doc/index.html">Boost.Pool</a> memory allocator by
42 default. Using this allocator does however introduce a few restrictions:
44 \li The operator is defined for a fixed size. Therefore if you derive from the class <b>you
45 must not change it's size</t>.
46 \li If you change the size of the class in a derived class you have to derive from
47 pool_alloc_mixin again.
52 : public senf::pool_alloc_mixin<SomeClass>
58 \note pool_alloc_mixin uses the <a
59 href="http://www.boost.org/libs/pool/doc/index.html">Boost.Pool</a> <i>singleton
60 pool</i> interface with the tag <tt>pool_alloc_mixin_tag</tt>. This class is accessible
61 via the <tt>pool</tt> member. Using this member, it is simple to call relevant pool
62 functions, e.g. <tt>SomeClass::pool<>::release_memory()</tt>.
65 class pool_alloc_mixin
68 /** \brief Templated typedef for the pool used
70 Since the instantiation of the typedef must be delayed until Self is completely defined,
71 the simple typedef is replaced with a nested struct.
73 template <class T=void>
75 : public boost::singleton_pool< pool_alloc_mixin_tag, sizeof(Self) >
77 typedef boost::singleton_pool< pool_alloc_mixin_tag, sizeof(Self) > type;
80 static void * operator new (size_t size);
81 ///< Operator new utilizing pool allocation
82 static void operator delete (void *p, size_t size);
83 ///< Operator delete utilizing pool allocation
86 static unsigned long allocCounter();
88 static unsigned long allocCounter(long delta);
94 ///////////////////////////////hh.e////////////////////////////////////////
95 //#include "pool_alloc_mixin.cci"
96 //#include "pool_alloc_mixin.ct"
97 #include "pool_alloc_mixin.cti"
104 // c-file-style: "senf"
105 // indent-tabs-mode: nil
106 // ispell-local-dictionary: "american"
107 // compile-command: "scons -u test"
108 // comment-column: 40