AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
memory_management.hpp File Reference
#include "axom/config.hpp"
#include "axom/core/Macros.hpp"
#include "axom/core/utilities/Utilities.hpp"
#include <cstring>
#include <cstdlib>
#include <cstddef>
#include <iostream>
#include <string>
#include <type_traits>

Classes

struct  axom::Allocator
 Wrapper type representing an Umpire allocator ID. More...
 

Namespaces

 axom
 
 axom::detail
 

Enumerations

enum class  axom::MemorySpace { axom::Malloc , axom::Dynamic , axom::Host }
 Memory spaces supported by Array-like types. More...
 
enum class  axom::detail::AllocationBackend { axom::detail::Malloc , axom::detail::Invalid }
 

Functions

bool axom::isValidAllocatorID (int allocatorId) noexcept
 Returns whether allocatorId is a valid Axom allocator id. More...
 
void axom::detail::registerMallocAllocation (const void *pointer, std::size_t numbytes) noexcept
 
void axom::detail::updateMallocAllocation (const void *oldPointer, const void *newPointer, std::size_t numbytes) noexcept
 
void axom::detail::unregisterMallocAllocation (const void *pointer) noexcept
 
bool axom::detail::tryGetMallocAllocationSize (const void *pointer, std::size_t &numbytes) noexcept
 
AllocationBackend axom::detail::getAllocatorBackend (int allocID) noexcept
 
template<typename T >
AllocationBackend axom::detail::getPointerBackend (T *pointer) noexcept
 
void axom::detail::abortOnInvalidAllocatorID (int allocID)
 
void axom::detail::abortOnInvalidReallocateState ()
 
void axom::detail::abortOnUntrackedMallocMigration (const void *pointer, int allocID)
 
template<typename T >
T * axom::detail::normalizeZeroSizeReallocateResult (T *pointer, std::size_t n, int allocID) noexcept
 
template<typename T >
T * axom::detail::reallocateWithinMalloc (T *pointer, std::size_t numbytes) noexcept
 
template<MemorySpace SPACE>
int axom::detail::getAllocatorID ()
 Translates between the MemorySpace enum and Umpire allocator IDs. More...
 
template<>
int axom::detail::getAllocatorID< MemorySpace::Dynamic > ()
 
template<>
int axom::detail::getAllocatorID< MemorySpace::Malloc > ()
 
MemorySpace axom::detail::getAllocatorSpace (int allocatorId)
 Return the Axom MemorySpace for the given Axom allocator id. More...
 
template<>
int axom::detail::getAllocatorID< MemorySpace::Host > ()
 
bool axom::isHostAccessibleAllocatorID (int allocId)
 Returns true if memory allocated by allocator with given ID is accessible on host; else return false. More...
 
bool axom::isDeviceAllocator (int AXOM_UNUSED_PARAM(allocator_id))
 Determines whether an allocator id is on device. More...
 
Memory Management Routines
bool axom::isMemorySpaceAvailable (MemorySpace space) noexcept
 Returns true if memory space is available in the current build. More...
 
int axom::getAllocatorIDFromMemorySpace (MemorySpace space)
 Returns the allocator ID corresponding to a memory space. More...
 
void axom::setDefaultAllocator (MemorySpace space)
 Sets the default memory allocator using an Axom MemorySpace enum value. More...
 
void axom::setDefaultHostAllocator (MemorySpace space)
 Sets the default host allocator using Axom MemorySpace enum value. More...
 
void axom::setDefaultHostAllocator (int allocId)
 Sets the default host allocator using an allocator ID. More...
 
void axom::setDefaultAllocator (int allocId)
 Sets the default memory allocator to use. More...
 
int axom::getDefaultAllocatorID ()
 Returns the ID of the current default Umpire allocator or MALLOC_ALLOCATOR_ID if Umpire is not used. More...
 
int axom::getDefaultHostAllocatorID ()
 Returns the ID of the current default host allocator. More...
 
bool axom::isAllocatorCompatibleWithMemorySpace (int allocId, MemorySpace space) noexcept
 Returns whether an allocator ID is compatible with a memory space. More...
 
int axom::getAllocatorIDFromPointer (const void *ptr)
 Get the allocator id from which data has been allocated. More...
 
bool axom::isSharedMemoryAllocator (int allocID)
 Determines whether an allocator id is for shared memory. More...
 
int axom::getSharedMemoryAllocatorID (std::size_t minSegmentSize=0)
 Get the allocator ID for Axom's shared memory allocator. More...
 
template<typename T >
T * axom::allocate (std::size_t n, int allocID=getDefaultAllocatorID()) noexcept
 Allocates a chunk of memory of type T. More...
 
template<typename T >
T * axom::allocate (std::size_t n, const std::string &name, int allocID=getDefaultAllocatorID()) noexcept
 Allocates a chunk of memory of type T with a user-supplied allocation name. More...
 
template<typename T >
void axom::deallocate (T *&p) noexcept
 Frees the chunk of memory pointed to by the supplied pointer, p. More...
 
template<typename T >
T * axom::reallocate (T *p, std::size_t n, int allocID=getDefaultAllocatorID()) noexcept
 Reallocates the chunk of memory pointed to by the supplied pointer. More...
 
void axom::copy (void *dst, const void *src, std::size_t numbytes) noexcept
 Copies memory from the source to the destination. More...
 
template<typename T >
void axom::fill (void *dst, std::size_t n, const T &value) noexcept
 Fills memory with a value. More...
 

Variables

constexpr int axom::INVALID_ALLOCATOR_ID = -1
 Place holder for no/unknown allocator. More...
 
constexpr int axom::MALLOC_ALLOCATOR_ID = -3
 Refers to MemorySpace::Malloc. More...