Xalan-C++ API Reference  1.12.0
XalanDiagnosticMemoryManager.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #if !defined(XALAN_DIAGNOSTICMEMORYMANAGER_HEADER_GUARD_1357924680)
19 #define XALAN_DIAGNOSTICMEMORYMANAGER_HEADER_GUARD_1357924680
20 
21 
22 
24 
25 
26 
27 #include <cstddef>
28 
29 
30 
31 #include <iosfwd>
32 #include <ios>
33 
34 
35 
38 
39 
40 
41 namespace XALAN_CPP_NAMESPACE {
42 
43 
44 
46 {
47 public:
48 
49  typedef std::ostream StreamType;
50 
52  {
53  public:
54 
56  {
57  }
58 
60  {
61  }
62  };
63 
65  MemoryManager& theMemoryManager,
66  bool fAssertErrors = false,
67  StreamType* theStream = 0);
68 
69  virtual
71 
72  virtual void*
73  allocate(size_type size);
74 
75  virtual void
76  deallocate(void* pointer);
77 
78  virtual MemoryManager*
79  getExceptionMemoryManager();
80 
81  bool
83  {
84  return m_assertErrors;
85  }
86 
87  void
88  setAssertErrors(bool fFlag)
89  {
90  m_assertErrors = fFlag;
91  }
92 
93  // Get the high-water mark (the highest amount
94  // that was allocated at any particular point).
95  size_type
97  {
98  return m_highWaterMark;
99  }
100 
101  // Get the number of bytes currently allocated.
102  size_type
103  getAllocated() const
104  {
105  return m_currentAllocated;
106  }
107 
108  // Get the current number of outstanding allocations.
109  size_type
111  {
112  return m_allocations.size();
113  }
114 
115  struct Data
116  {
117  Data() :
118  m_size(0),
119  m_sequence(0)
120  {
121  }
122 
124  size_type theSize,
125  size_type theSequence) :
126  m_size(theSize),
127  m_sequence(theSequence)
128  {
129  }
130 
132 
134  };
135 
137 
139 
142  {
143  return m_allocations.begin();
144  }
145 
146  void
148  {
149  m_locked = true;
150  }
151 
152  void
154  {
155  m_locked = false;
156  }
157 
158  enum
159  {
160  defaultBytesToDump = 20u
161  };
162 
163  void
164  dumpStatistics(
165  StreamType* theStream = 0,
166  size_type theBytesToDump = defaultBytesToDump);
167 
168 private:
169 
171 
173  operator=(const XalanDiagnosticMemoryManager&);
174 
175  MemoryManager& m_memoryManager;
176 
177  bool m_assertErrors;
178 
179  bool m_locked;
180 
181  size_type m_sequence;
182 
183  size_type m_highWaterMark;
184 
185  size_type m_currentAllocated;
186 
187  MapType m_allocations;
188 
189  StreamType* m_stream;
190 };
191 
192 
193 
194 }
195 
196 
197 
198 #endif // XALAN_DIAGNOSTICMEMORYMANAGER_HEADER_GUARD_1357924680
XALAN_HARNESS_EXPORT
#define XALAN_HARNESS_EXPORT
Definition: XalanHarnessDefinitions.hpp:27
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanDiagnosticMemoryManager::LockException
Definition: XalanDiagnosticMemoryManager.hpp:51
xalanc::XalanDiagnosticMemoryManager::getAllocations
size_type getAllocations() const
Definition: XalanDiagnosticMemoryManager.hpp:110
xalanc::XalanDiagnosticMemoryManager::Data::m_sequence
size_type m_sequence
Definition: XalanDiagnosticMemoryManager.hpp:133
xalanc::XalanDiagnosticMemoryManager::LockException::LockException
LockException()
Definition: XalanDiagnosticMemoryManager.hpp:55
xalanc::XalanMemoryManager::size_type
std::size_t size_type
Definition: XalanMemoryManagement.hpp:51
xalanc::XalanDiagnosticMemoryManager::const_iterator
MapType::const_iterator const_iterator
Definition: XalanDiagnosticMemoryManager.hpp:138
xalanc::XalanMemoryManager
Definition: XalanMemoryManagement.hpp:46
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::XalanDiagnosticMemoryManager::Data::m_size
size_type m_size
Definition: XalanDiagnosticMemoryManager.hpp:131
xalanc::XalanDiagnosticMemoryManager::MapType
XalanMap< void *, Data > MapType
Definition: XalanDiagnosticMemoryManager.hpp:136
xalanc::XalanDiagnosticMemoryManager
Definition: XalanDiagnosticMemoryManager.hpp:45
XalanHarnessDefinitions.hpp
XalanMemoryManagement.hpp
xalanc::XalanDiagnosticMemoryManager::unlock
void unlock()
Definition: XalanDiagnosticMemoryManager.hpp:153
xalanc::XalanDiagnosticMemoryManager::StreamType
std::ostream StreamType
Definition: XalanDiagnosticMemoryManager.hpp:49
xalanc::XalanDiagnosticMemoryManager::lock
void lock()
Definition: XalanDiagnosticMemoryManager.hpp:147
xalanc::XalanDiagnosticMemoryManager::getAllocationsIterator
const_iterator getAllocationsIterator() const
Definition: XalanDiagnosticMemoryManager.hpp:141
xalanc::XalanDiagnosticMemoryManager::getHighWaterMark
size_type getHighWaterMark() const
Definition: XalanDiagnosticMemoryManager.hpp:96
xalanc::XalanDiagnosticMemoryManager::getAllocated
size_type getAllocated() const
Definition: XalanDiagnosticMemoryManager.hpp:103
xalanc::XalanDiagnosticMemoryManager::Data
Definition: XalanDiagnosticMemoryManager.hpp:115
xalanc::XalanMap< void *, Data >
xalanc::XalanDiagnosticMemoryManager::Data::Data
Data()
Definition: XalanDiagnosticMemoryManager.hpp:117
XalanMap.hpp
xalanc::XalanDiagnosticMemoryManager::setAssertErrors
void setAssertErrors(bool fFlag)
Definition: XalanDiagnosticMemoryManager.hpp:88
xalanc::XalanMapIterator
Definition: XalanMap.hpp:115
xalanc::XalanDiagnosticMemoryManager::Data::Data
Data(size_type theSize, size_type theSequence)
Definition: XalanDiagnosticMemoryManager.hpp:123
xalanc::XalanDiagnosticMemoryManager::getAssertErrors
bool getAssertErrors() const
Definition: XalanDiagnosticMemoryManager.hpp:82
xalanc::XalanDiagnosticMemoryManager::LockException::~LockException
~LockException()
Definition: XalanDiagnosticMemoryManager.hpp:59