File util/memory.hpp

struct DefaultMemoryAllocator
#include <memory.hpp>

Provides functions for allocating memory.

Public Static Functions

template<typename T>
static inline T *allocateMemory(uint32 numElements, bool init = false)

Allocates memory to be used by an array of a specific size.

Template Parameters:

T – The type of the values stored in the array

Parameters:
  • numElements – The number of elements in the array

  • init – True, if all elements in the array should be default-initialized, false otherwise

Returns:

A pointer to the allocated memory

template<typename T>
static inline T *reallocateMemory(T *array, uint32 previousElements, uint32 newElements)

Reallocates the memory used by an array in order to resize it.

Template Parameters:

T – The type of the values stored in the array

Parameters:
  • array – A pointer to an array of template type T

  • previousElements – The number of elements in the original array

  • newElements – The number of elements in the resized array

Returns:

A pointer to the reallocated memory

template<typename T>
static inline void freeMemory(T *array)

Frees the memory used by an array.

Template Parameters:

T – The type of the values stored in the array

Parameters:

array – A pointer to an array of template type T