39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
87 size_t m_num_total_values{0};
88 size_t m_num_total_reserved{0};
89 size_t m_num_allocated{0};
93 void allocate_internal(
size_t n );
96 void memory_exausted(
size_t sz );
99 void pop_exausted(
size_t sz );
115 : m_name(std::move(name))
130 template <
typename T2>
133 static_assert(std::is_integral<T2>::value,
"allocate() accepts only integral types!");
143 template <
typename T2>
146 static_assert(std::is_integral<T2>::value,
"reallocate() accepts only integral types!");
151 void free() { m_num_total_values = m_num_allocated = 0; }
160 size_t size()
const {
return m_num_total_values; }
168 size_t offs = m_num_allocated;
169 m_num_allocated += sz;
170 if ( m_num_allocated > m_num_total_values ) memory_exausted( sz );
171 return m_p_memory + offs;
174 template <
typename T2>
176 static_assert(std::is_integral<T2>::value,
"operator() accepts only integral types!");
177 return (*
this)(
static_cast<size_t>(sz));
185 if ( sz > m_num_allocated ) pop_exausted( sz );
186 m_num_allocated -= sz;
189 template <
typename T2>
192 static_assert(std::is_integral<T2>::value,
"pop() accepts only integral types!");
193 pop(
static_cast<size_t>(n));
203 template <
typename T2>
206 static_assert(std::is_integral<T2>::value,
"malloc() accepts only integral types!");
207 return malloc(
static_cast<size_t>(n));
217 template <
typename T2>
220 static_assert(std::is_integral<T2>::value,
"realloc() accepts only integral types!");
221 return realloc(
static_cast<size_t>(n));
228 bool is_empty()
const {
return m_num_allocated >= m_num_total_values; }
241 string info( string_view where )
const;
281 template <
typename T, std::
size_t mem_size>
290 size_t m_num_allocated{0};
291 valueType m_data[mem_size];
307 : m_name(std::move(name))
314 void free() { m_num_allocated = 0; }
320 static size_t size() {
return mem_size; }
327 T * operator () (
size_t sz );
339 bool is_empty()
const {
return m_num_allocated >= mem_size; }
MallocFixed(string name)
Constructor.
Definition Malloc.hxx:306
void free()
Free memory without deallocating the pointer.
Definition Malloc.hxx:314
~MallocFixed()=default
Destructor.
bool is_empty() const
Check if the memory is fully allocated.
Definition Malloc.hxx:339
void pop(size_t sz)
Free memory for sz objects.
MallocFixed(MallocFixed< T, mem_size > const &)=delete
Copy constructor is deleted.
static size_t size()
Get the number of allocated objects.
Definition Malloc.hxx:320
T valueType
Type alias for the type of objects managed by this allocator.
Definition Malloc.hxx:285
Class for dynamic memory allocation of objects.
Definition Malloc.hxx:79
void allocate(size_t n)
Allocate memory for n objects, error if already allocated.
T valueType
Type alias for the type of objects managed by this allocator.
Definition Malloc.hxx:82
~Malloc()
Destructor.
Definition Malloc.hxx:122
bool is_empty() const
Check if the memory is fully allocated.
Definition Malloc.hxx:228
void must_be_empty(string_view where) const
Ensure that memory is fully used.
void hard_free()
Free memory and deallocate the pointer.
size_t size() const
Get the number of allocated objects.
Definition Malloc.hxx:160
void free()
Free memory without deallocating the pointer.
Definition Malloc.hxx:151
Malloc(Malloc< T > const &)=delete
Copy constructor is deleted.
void allocate(T2 n)
Definition Malloc.hxx:132
string info(string_view where) const
Get memory allocation information.
Malloc(string name)
Constructor.
Definition Malloc.hxx:114
void reallocate(size_t n)
Reallocate memory for n objects, even if already allocated.
void pop(size_t sz)
Free memory for sz objects.
Definition Malloc.hxx:184
Malloc< T > const & operator=(Malloc< T > const &) const =delete
Assignment operator is deleted.
T * realloc(size_t n)
Reallocate memory for n objects.
T * realloc(T2 n)
Definition Malloc.hxx:219
void pop(T2 n)
Definition Malloc.hxx:191
T * malloc(size_t n)
Allocate memory for n objects.
T * malloc(T2 n)
Definition Malloc.hxx:205
T * operator()(size_t sz)
Allocate memory for sz objects and return the pointer.
Definition Malloc.hxx:167
void reallocate(T2 n)
Definition Malloc.hxx:145
std::mutex MallocMutex
Global mutex for thread-safe memory operations.
int64_t CountAlloc
Global variables for tracking memory allocation statistics.
int64_t MaximumAllocatedBytes
string out_bytes(size_t nb)
Utility function to convert byte size into a human-readable format.
Definition SystemUtils.cc:39