![]() |
UtilsLite
Utilities for C++ programming
|
Class for dynamic memory allocation of objects. More...
#include <Malloc.hxx>
Public Types | |
| using | valueType = T |
| Type alias for the type of objects managed by this allocator. | |
Public Member Functions | |
| Malloc (Malloc< T > const &)=delete | |
| Copy constructor is deleted. | |
| Malloc< T > const & | operator= (Malloc< T > const &) const =delete |
| Assignment operator is deleted. | |
| Malloc (string name) | |
| Constructor. | |
| ~Malloc () | |
| Destructor. | |
| void | allocate (size_t n) |
Allocate memory for n objects, error if already allocated. | |
| template<typename T2> | |
| void | allocate (T2 n) |
| void | reallocate (size_t n) |
Reallocate memory for n objects, even if already allocated. | |
| template<typename T2> | |
| void | reallocate (T2 n) |
| void | free () |
| Free memory without deallocating the pointer. | |
| void | hard_free () |
| Free memory and deallocate the pointer. | |
| size_t | size () const |
| Get the number of allocated objects. | |
| T * | operator() (size_t sz) |
Allocate memory for sz objects and return the pointer. | |
| template<typename T2> | |
| T * | operator() (T2 sz) |
| void | pop (size_t sz) |
Free memory for sz objects. | |
| template<typename T2> | |
| void | pop (T2 n) |
| T * | malloc (size_t n) |
Allocate memory for n objects. | |
| template<typename T2> | |
| T * | malloc (T2 n) |
| T * | realloc (size_t n) |
Reallocate memory for n objects. | |
| template<typename T2> | |
| T * | realloc (T2 n) |
| bool | is_empty () const |
| Check if the memory is fully allocated. | |
| void | must_be_empty (string_view where) const |
| Ensure that memory is fully used. | |
| string | info (string_view where) const |
| Get memory allocation information. | |
Class for dynamic memory allocation of objects.
This class provides custom memory management utilities for allocating, freeing, and managing dynamic memory for objects of type T.
| T | The type of objects to allocate. |
| using Utils::Malloc< T >::valueType = T |
Type alias for the type of objects managed by this allocator.
|
delete |
Copy constructor is deleted.
|
inlineexplicit |
Constructor.
| name | A string identifier for the allocated memory block. |
|
inline |
Destructor.
Frees the allocated memory.
| void Utils::Malloc< T >::allocate | ( | size_t | n | ) |
Allocate memory for n objects, error if already allocated.
| n | Number of objects to allocate. |
|
inline |
Free memory without deallocating the pointer.
| void Utils::Malloc< T >::hard_free | ( | ) |
Free memory and deallocate the pointer.
| string Utils::Malloc< T >::info | ( | string_view | where | ) | const |
Get memory allocation information.
| where | Identifier for where the information is retrieved. |
|
inline |
Check if the memory is fully allocated.
true if all memory is allocated, false otherwise. | T * Utils::Malloc< T >::malloc | ( | size_t | n | ) |
Allocate memory for n objects.
| n | Number of objects to allocate. |
| void Utils::Malloc< T >::must_be_empty | ( | string_view | where | ) | const |
Ensure that memory is fully used.
| where | Identifier for where the check is performed. |
|
inline |
Allocate memory for sz objects and return the pointer.
| sz | Number of objects to allocate. |
|
delete |
Assignment operator is deleted.
|
inline |
Free memory for sz objects.
| sz | Number of objects to free. |
| T * Utils::Malloc< T >::realloc | ( | size_t | n | ) |
Reallocate memory for n objects.
| n | Number of objects to reallocate. |
| void Utils::Malloc< T >::reallocate | ( | size_t | n | ) |
Reallocate memory for n objects, even if already allocated.
| n | Number of objects to reallocate. |
|
inline |
Get the number of allocated objects.