15 #if !defined(KRATOS_MEMORY_POOL_H_INCLUDED )
16 #define KRATOS_MEMORY_POOL_H_INCLUDED
77 static void*
Allocate(std::size_t ObjectSizeInBytes) {
81 static void Deallocate(
void* pPointrerToRelease, std::size_t ObjectSizeInBytes) {
103 if (r_pools.size() <= BlockSize) {
106 if (r_pools.size() <= BlockSize)
107 r_pools.resize(BlockSize + 1,
nullptr);
111 if (r_pools[BlockSize] ==
nullptr) {
114 if (r_pools[BlockSize] ==
nullptr)
118 return r_pools[BlockSize];
132 if(*i_pool !=
nullptr)
133 result += (*i_pool)->MemoryUsed();
140 if (*i_pool !=
nullptr)
141 result += (*i_pool)->MemoryOverhead();
151 std::stringstream buffer(
"MemoryPool");
154 double overhead_percentage = memory_overhead;
155 if (memory_overhead < memory_used)
156 overhead_percentage =
static_cast<double>(memory_overhead)/(memory_used - memory_overhead);
157 overhead_percentage *= 100.00;
159 buffer <<
"Total memory usage: "
160 << SizeInBytesToString(
MemoryUsed()) <<
" bytes and memory overhead "
161 << SizeInBytesToString(
MemoryOverhead()) <<
"(" << overhead_percentage <<
"%)" << std::endl;
188 static std::string SizeInBytesToString(std::size_t Bytes) {
189 std::stringstream buffer;
190 double result = Bytes;
191 constexpr
int units_size = 5;
192 constexpr
char units[units_size+1] = {
' ',
'k',
'M',
'G',
'T',
'T'};
194 for (;
i < units_size;
i++)
201 buffer << result << units[
i];
FixedSizeMemoryPool is the multi-thread manager of Kratos memory management.
Definition: fixed_size_memory_pool.h:40
void * Allocate()
This function does not throw and returns zero if cannot allocate.
Definition: fixed_size_memory_pool.h:86
void Deallocate(void *pPointrerToRelease)
Definition: fixed_size_memory_pool.h:91
MemoryPool is the smallest building block of Kratos memory management.
Definition: memory_pool.h:38
static FixedSizeMemoryPool * GetPoolWithBlockSize(std::size_t BlockSize)
Definition: memory_pool.h:99
virtual ~MemoryPool()
Destructor.
Definition: memory_pool.h:53
std::vector< FixedSizeMemoryPool * > PoolsContainerType
Definition: memory_pool.h:43
static std::size_t GetNumberOfPools()
Definition: memory_pool.h:95
static std::size_t MemoryOverhead()
Definition: memory_pool.h:137
MemoryPool & operator=(MemoryPool const &rOther)=delete
Assignment operator is deleted.
MemoryPool(MemoryPool const &rOther)=delete
Copy constructor is deleted.
static void Deallocate(void *pPointrerToRelease, std::size_t ObjectSizeInBytes)
Definition: memory_pool.h:81
static std::string Info()
Turn back information as a string.
Definition: memory_pool.h:150
static MemoryPool & GetInstance()
Definition: memory_pool.h:90
static std::size_t MemoryUsed()
Definition: memory_pool.h:129
static void * Allocate(std::size_t ObjectSizeInBytes)
Definition: memory_pool.h:77
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
integer i
Definition: TensorModule.f:17