1#ifndef UTIL_MEMORY_COUNTER_H
2#define UTIL_MEMORY_COUNTER_H
13#include <util/space/Vector.h>
14#include <util/space/IntVector.h>
86 template <
typename T,
size_t N>
94 template <
typename T,
size_t N>
104 template <
typename T>
105 void count(
const T& data);
114 template <
typename T>
115 void count(T* array,
int n);
142 friend void serialize<>(
MemoryCounter&, std::string&,
const unsigned int);
149 template <
typename T>
154 return counter.
size();
174 template <
typename T>
177 serialize(*
this, data, version_);
184 template <
typename T>
187 serialize(*
this, data, version_);
194 template <
typename T,
size_t N>
197 for (
size_t i = 0; i < N; ++i) {
198 serialize(*
this, data[i], version_);
206 template <
typename T,
size_t N>
209 for (
size_t i = 0; i < N; ++i) {
210 serialize(*
this, data[i], version_);
220 template <
typename T>
222 { size_ +=
sizeof(T); }
227 template <
typename T>
229 { size_ += n*
sizeof(T); }
241 const unsigned int version)
248 inline void serialize(MemoryCounter& ar,
char& data,
249 const unsigned int version)
256 inline void serialize(MemoryCounter& ar,
unsigned int& data,
257 const unsigned int version)
264 inline void serialize(MemoryCounter& ar,
int& data,
265 const unsigned int version)
272 inline void serialize(MemoryCounter& ar,
unsigned long& data,
273 const unsigned int version)
280 inline void serialize(MemoryCounter& ar,
long& data,
281 const unsigned int version)
288 inline void serialize(MemoryCounter& ar,
float& data,
289 const unsigned int version)
296 inline void serialize(MemoryCounter& ar,
double& data,
297 const unsigned int version)
306 inline void serialize(MemoryCounter& ar, std::complex<float>& data,
307 const unsigned int version)
314 inline void serialize(MemoryCounter& ar, std::complex<double>& data,
315 const unsigned int version)
322 inline void serialize(MemoryCounter& ar, std::string& data,
323 const unsigned int version)
324 { ar.size_ +=
sizeof(size_t) + (data.size() + 1)*
sizeof(char); }
332 inline void serialize(MemoryCounter& ar, Vector& data,
333 const unsigned int version)
340 inline void serialize(MemoryCounter& ar, IntVector& data,
341 const unsigned int version)
Archive to computed packed size of a sequence of objects, in bytes.
MemoryCounter()
Constructor.
MemoryCounter & operator<<(T &data)
Add packed size of one object via operator <<.
~MemoryCounter()
Destructor.
static bool is_loading()
Returns false.
static bool is_saving()
Returns true.
size_t size() const
Return size required for archive, in Bytes.
void count(const T &data)
Add size of one object in memory.
void clear()
Resets the size counter to zero.
MemoryCounter & operator&(T &data)
Add packed size of one object via operator &.
Utility classes for scientific computation.
int memorySize(T &data)
Function template to compute memory size of one object.