UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
Utils::Malloc< T > Class Template Reference

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.
 

Detailed Description

template<typename T>
class Utils::Malloc< T >

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.

Template Parameters
TThe type of objects to allocate.

Member Typedef Documentation

◆ valueType

template<typename T>
using Utils::Malloc< T >::valueType = T

Type alias for the type of objects managed by this allocator.

Constructor & Destructor Documentation

◆ Malloc() [1/2]

template<typename T>
Utils::Malloc< T >::Malloc ( Malloc< T > const & )
delete

Copy constructor is deleted.

◆ Malloc() [2/2]

template<typename T>
Utils::Malloc< T >::Malloc ( string name)
inlineexplicit

Constructor.

Parameters
nameA string identifier for the allocated memory block.

◆ ~Malloc()

template<typename T>
Utils::Malloc< T >::~Malloc ( )
inline

Destructor.

Frees the allocated memory.

Member Function Documentation

◆ allocate() [1/2]

template<typename T>
void Utils::Malloc< T >::allocate ( size_t n)

Allocate memory for n objects, error if already allocated.

Parameters
nNumber of objects to allocate.

◆ allocate() [2/2]

template<typename T>
template<typename T2>
void Utils::Malloc< T >::allocate ( T2 n)
inline

◆ free()

template<typename T>
void Utils::Malloc< T >::free ( )
inline

Free memory without deallocating the pointer.

◆ hard_free()

template<typename T>
void Utils::Malloc< T >::hard_free ( )

Free memory and deallocate the pointer.

◆ info()

template<typename T>
string Utils::Malloc< T >::info ( string_view where) const

Get memory allocation information.

Parameters
whereIdentifier for where the information is retrieved.
Returns
A string containing information about memory allocation.

◆ is_empty()

template<typename T>
bool Utils::Malloc< T >::is_empty ( ) const
inline

Check if the memory is fully allocated.

Returns
true if all memory is allocated, false otherwise.

◆ malloc() [1/2]

template<typename T>
T * Utils::Malloc< T >::malloc ( size_t n)

Allocate memory for n objects.

Parameters
nNumber of objects to allocate.
Returns
Pointer to the allocated memory.

◆ malloc() [2/2]

template<typename T>
template<typename T2>
T * Utils::Malloc< T >::malloc ( T2 n)
inline

◆ must_be_empty()

template<typename T>
void Utils::Malloc< T >::must_be_empty ( string_view where) const

Ensure that memory is fully used.

Parameters
whereIdentifier for where the check is performed.

◆ operator()() [1/2]

template<typename T>
T * Utils::Malloc< T >::operator() ( size_t sz)
inline

Allocate memory for sz objects and return the pointer.

Parameters
szNumber of objects to allocate.
Returns
Pointer to the allocated memory.

◆ operator()() [2/2]

template<typename T>
template<typename T2>
T * Utils::Malloc< T >::operator() ( T2 sz)
inline

◆ operator=()

template<typename T>
Malloc< T > const & Utils::Malloc< T >::operator= ( Malloc< T > const & ) const
delete

Assignment operator is deleted.

◆ pop() [1/2]

template<typename T>
void Utils::Malloc< T >::pop ( size_t sz)
inline

Free memory for sz objects.

Parameters
szNumber of objects to free.

◆ pop() [2/2]

template<typename T>
template<typename T2>
void Utils::Malloc< T >::pop ( T2 n)
inline

◆ realloc() [1/2]

template<typename T>
T * Utils::Malloc< T >::realloc ( size_t n)

Reallocate memory for n objects.

Parameters
nNumber of objects to reallocate.
Returns
Pointer to the reallocated memory.

◆ realloc() [2/2]

template<typename T>
template<typename T2>
T * Utils::Malloc< T >::realloc ( T2 n)
inline

◆ reallocate() [1/2]

template<typename T>
void Utils::Malloc< T >::reallocate ( size_t n)

Reallocate memory for n objects, even if already allocated.

Parameters
nNumber of objects to reallocate.

◆ reallocate() [2/2]

template<typename T>
template<typename T2>
void Utils::Malloc< T >::reallocate ( T2 n)
inline

◆ size()

template<typename T>
size_t Utils::Malloc< T >::size ( ) const
inline

Get the number of allocated objects.

Returns
Number of currently allocated objects.

The documentation for this class was generated from the following file: