SolidUtils
Static Public Member Functions | List of all members
sl::Alloc Class Reference

The Alloc class provides a set of static functions for allocating templated memory via malloc() and associated functions. More...

#include <Alloc.hpp>

Static Public Member Functions

template<typename T >
static T * uninitialized (size_t const num)
 Allocate a block of uninitialized memory that can be free'd with a call to Alloc::free(). If the amount of memory requested is 0, then nullptr will be returned. More...
 
template<typename T >
static T * initialized (size_t const num, T const val=static_cast< T >(0))
 Allocate and initialize a block of memory to a constant value. More...
 
template<typename T >
static T * duplicate (T const *const ptr, size_t const num)
 Allocate and and fill a block of memory from another block. More...
 
template<typename T >
static void resize (T **const ptr, size_t const num)
 Resize an allocation. More...
 
template<typename T >
static void free (T *const ptr) noexcept
 Free a block of memory allocated with this class. More...
 

Detailed Description

The Alloc class provides a set of static functions for allocating templated memory via malloc() and associated functions.

Member Function Documentation

◆ duplicate()

template<typename T >
static T* sl::Alloc::duplicate ( T const *const  ptr,
size_t const  num 
)
inlinestatic

Allocate and and fill a block of memory from another block.

Template Parameters
TThe type of memory to allocate.
Parameters
ptrThe other bock of memory.
numThe size of the other block (in terms of elements).
Returns
The memory.
Exceptions
std::bad_allocIf the amount of memory fails to get allocated.

◆ free()

template<typename T >
static void sl::Alloc::free ( T *const  ptr)
inlinestaticnoexcept

Free a block of memory allocated with this class.

Template Parameters
TThe type of memory to free.
Parameters
ptrA pointer to the memory to free.

◆ initialized()

template<typename T >
static T* sl::Alloc::initialized ( size_t const  num,
T const  val = static_cast<T>(0) 
)
inlinestatic

Allocate and initialize a block of memory to a constant value.

Template Parameters
TThe type of memory to allocate.
Parameters
numThe number of elements.
valThe value to initialize elements to.
Returns
The memory.
Exceptions
std::bad_allocIf the amount of memory fails to get allocated.

◆ resize()

template<typename T >
static void sl::Alloc::resize ( T **const  ptr,
size_t const  num 
)
inlinestatic

Resize an allocation.

Template Parameters
TThe type of element.
Parameters
ptrThe pointer to resize.
numThe number of elements.
Exceptions
std::bad_allocIf the amount of memory fails to get allocated.

◆ uninitialized()

template<typename T >
static T* sl::Alloc::uninitialized ( size_t const  num)
inlinestatic

Allocate a block of uninitialized memory that can be free'd with a call to Alloc::free(). If the amount of memory requested is 0, then nullptr will be returned.

Template Parameters
TThe type of memory to allocate.
Parameters
numThe number of elements.
Returns
The memory.
Exceptions
std::bad_allocIf the amount of memory fails to get allocated.

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