reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
DinkyPool.hxx
Go to the documentation of this file.
1#ifndef DinkyPool_Include_Guard
2#define DinkyPool_Include_Guard
3
4#include <limits>
5#include <memory>
6#include <stddef.h>
7
8#include "rutil/PoolBase.hxx"
9
10namespace resip
11{
19template<unsigned int S>
20class DinkyPool : public PoolBase
21{
22 public:
23 DinkyPool() : count(0), heapBytes(0) {}
25
26 void* allocate(size_t size)
27 {
28 if((8*count)+size <= S)
29 {
30 void* result=mBuf[count];
31 count+=(size+7)/8;
32 return result;
33 }
34 heapBytes += size;
35 return ::operator new(size);
36 }
37
38 void deallocate(void* ptr)
39 {
40 if(ptr >= (void*)mBuf[0] && ptr < (void*)mBuf[(S+7)/8])
41 {
42 return;
43 }
44 ::operator delete(ptr);
45 }
46
47 size_t max_size() const
48 {
49 return std::numeric_limits<size_t>::max();
50 }
51
52 size_t getHeapBytes() const { return heapBytes; }
53 size_t getPoolBytes() const { return count*8; }
54 size_t getPoolSizeBytes() const { return sizeof(mBuf); }
55
56 private:
57 // disabled
58 DinkyPool& operator=(const DinkyPool& rhs);
59 DinkyPool(const DinkyPool& other);
60
61 size_t count; // 8-byte chunks alloced so far
62 char mBuf[(S+7)/8][8]; // 8-byte chunks for alignment
63 size_t heapBytes;
64};
65
66}
67#endif
68
69
70/* ====================================================================
71 * The Vovida Software License, Version 1.0
72 *
73 * Redistribution and use in source and binary forms, with or without
74 * modification, are permitted provided that the following conditions
75 * are met:
76 *
77 * 1. Redistributions of source code must retain the above copyright
78 * notice, this list of conditions and the following disclaimer.
79 *
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in
82 * the documentation and/or other materials provided with the
83 * distribution.
84 *
85 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
86 * and "Vovida Open Communication Application Library (VOCAL)" must
87 * not be used to endorse or promote products derived from this
88 * software without prior written permission. For written
89 * permission, please contact vocal@vovida.org.
90 *
91 * 4. Products derived from this software may not be called "VOCAL", nor
92 * may "VOCAL" appear in their name, without prior written
93 * permission of Vovida Networks, Inc.
94 *
95 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
96 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
97 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
98 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
99 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
100 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
101 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
102 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
103 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
104 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
105 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
106 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
107 * DAMAGE.
108 *
109 * ====================================================================
110 *
111 * This software consists of voluntary contributions made by Vovida
112 * Networks, Inc. and many individuals on behalf of Vovida Networks,
113 * Inc. For more information on Vovida Networks, Inc., please see
114 * <http://www.vovida.org/>.
115 *
116 */
A dirt-simple lightweight pool allocator meant for use in short-lifetime objects.
Definition DinkyPool.hxx:21
size_t getPoolSizeBytes() const
Definition DinkyPool.hxx:54
size_t getPoolBytes() const
Definition DinkyPool.hxx:53
size_t getHeapBytes() const
Definition DinkyPool.hxx:52
void * allocate(size_t size)
Definition DinkyPool.hxx:26
void deallocate(void *ptr)
Definition DinkyPool.hxx:38
size_t max_size() const
Definition DinkyPool.hxx:47
dcm! – add UnusedChecking(_enum) below;