pool_alloc_mixin.cti
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief pool_alloc_mixin inline template implementation */
16 
17 //#include "pool_alloc_mixin.ih"
18 
19 // Custom includes
20 #include <senf/Utils/senfassert.hh>
21 
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 template <class Self>
26 prefix_ void * senf::pool_alloc_mixin<Self>::operator new(size_t size)
27 {
28  // When deriving from Self you may not change the class's size without
29  // inheriting from pool_alloc_mixin again. See pool_alloc_mixin documentation.
30  SENF_ASSERT( size <= sizeof(Self),
31  "senf::pool_alloc_mixin::operator new(): "
32  "Bad object size. Missing pool_alloc_mixin base in derived class?" );
33 #ifdef SENF_DEBUG
34  allocCounter(1);
35 #endif
36  return boost::singleton_pool< pool_alloc_mixin_tag, sizeof(Self) >::malloc();
37 }
38 
39 template <class Self>
40 prefix_ void senf::pool_alloc_mixin<Self>::operator delete(void * p, size_t size)
41 {
42 #ifdef SENF_DEBUG
43  allocCounter(-1);
44 #endif
45  boost::singleton_pool< pool_alloc_mixin_tag, sizeof(Self) >::free(p);
46 }
47 
48 #ifdef SENF_DEBUG
49 
50 template <class Self>
51 prefix_ unsigned long senf::pool_alloc_mixin<Self>::allocCounter()
52 {
53  return allocCounter(0);
54 }
55 
56 template <class Self>
57 prefix_ unsigned long senf::pool_alloc_mixin<Self>::allocCounter(long delta)
58 {
59  static unsigned long counter (0);
60  counter += delta;
61  return counter;
62 }
63 
64 #endif
65 
66 //-/////////////////////////////////////////////////////////////////////////////////////////////////
67 #undef prefix_
68 
69 
70 // Local Variables:
71 // mode: c++
72 // fill-column: 100
73 // c-file-style: "senf"
74 // indent-tabs-mode: nil
75 // ispell-local-dictionary: "american"
76 // compile-command: "scons -u test"
77 // comment-column: 40
78 // End: