MDL SDK API nvidia_logo_transpbg.gif Up
Memory Management

The memory management provides an interface for allocators including a default implementation. More...

Classes

class  mi::base::Default_allocator
 A default allocator implementation based on global new and delete. More...
 
class  mi::base::IAllocator
 The IAllocator interface class supports allocating and releasing memory dynamically. More...
 
class  mi::base::Std_allocator<T>
 An adaptor class template that implements a standard STL allocator. More...
 
struct  mi::base::Std_allocator<T>::rebind<T1>
 Rebind helper struct to define a new class instance of this allocator template instantiated for the new value type T1. More...
 

Typedefs

using mi::base::Std_allocator<T>::value_type = T
 Value type allocated by this allocator. More...
 
using mi::base::Std_allocator<T>::pointer = T *
 Pointer type. More...
 
using mi::base::Std_allocator<T>::const_pointer = const T *
 Const pointer type. More...
 
using mi::base::Std_allocator<T>::reference = T &
 Reference type. More...
 
using mi::base::Std_allocator<T>::const_reference = const T &
 Const reference type. More...
 
using mi::base::Std_allocator<T>::size_type = std::size_t
 Size type. More...
 
using mi::base::Std_allocator<T>::difference_type = std::ptrdiff_t
 Difference type. More...
 
using mi::base::Std_allocator<T>::rebind<T1>::other = Std_allocator<T1>
 Rebind type, defines a new class instance of this allocator template instantiated for the new value type T1. More...
 

Functions

void * mi::base::Default_allocator::malloc (Size size) override
 Allocates a memory block of the given size. More...
 
void mi::base::Default_allocator::free (void *memory) override
 Releases the given memory block. More...
 
static IAllocatormi::base::Default_allocator::get_instance ()
 Returns the single instance of the default allocator. More...
 
virtual void * mi::base::IAllocator::malloc (Size size)=0
 Allocates a memory block of the given size. More...
 
virtual void mi::base::IAllocator::free (void *memory)=0
 Releases the given memory block. More...
 
 mi::base::Std_allocator<T>::Std_allocator () noexcept
 Default constructor. More...
 
 mi::base::Std_allocator<T>::Std_allocator (base::IAllocator *allocator) noexcept
 Constructor. More...
 
template<class T1>
 mi::base::Std_allocator<T>::Std_allocator (const Std_allocator<T1> &other) noexcept
 Copying constructor template for alike allocators of different value type. More...
 
pointer mi::base::Std_allocator<T>::address (reference x) const
 Returns address of object x allocated through this allocator. More...
 
const_pointer mi::base::Std_allocator<T>::address (const_reference x) const
 Returns const address of object x allocated through this allocator. More...
 
T * mi::base::Std_allocator<T>::allocate (size_type n, const void *=nullptr) noexcept
 Allocate uninitialized dynamic memory for n elements of type T. More...
 
void mi::base::Std_allocator<T>::deallocate (pointer p, size_type)
 Frees uninitialized dynamic memory at location p that has previously been allocated with allocate(). More...
 
size_type mi::base::Std_allocator<T>::max_size () const noexcept
 Returns the maximum number of elements of type T that can be allocated using this allocator. More...
 
void mi::base::Std_allocator<T>::construct (pointer p, const_reference value)
 Calls the copy constructor of T on the location p with the argument value. More...
 
void mi::base::Std_allocator<T>::destroy (pointer p)
 Calls the destructor of T on the location p. More...
 
IAllocatormi::base::Std_allocator<T>::get_allocator () const
 Returns the interface of the underlying allocator. More...
 
template<class T2>
bool mi::base::Std_allocator<T>::operator== (Std_allocator<T2> other) const noexcept
 Equality comparison. More...
 
template<class T2>
bool mi::base::Std_allocator<T>::operator!= (Std_allocator<T2> other) const noexcept
 Inequality comparison. More...
 

Detailed Description

The memory management provides an interface for allocators including a default implementation.

You can request dynamic memory from an allocator implementation through an mi::base::IAllocator interface. A default implementation based on global new and delete operators is mi::base::Default_allocator.

You can adapt an allocator to become a standard STL allocator using mi::base::Std_allocator.

Typedef Documentation

 const_pointer

template<class T>
using mi::base::Std_allocator<T>::const_pointer = const T*

Const pointer type.

 const_reference

template<class T>
using mi::base::Std_allocator<T>::const_reference = const T&

Const reference type.

 difference_type

template<class T>
using mi::base::Std_allocator<T>::difference_type = std::ptrdiff_t

Difference type.

 other

template<class T>
template<class T1>
using mi::base::Std_allocator<T>::rebind<T1>::other = Std_allocator<T1>

Rebind type, defines a new class instance of this allocator template instantiated for the new value type T1.

 pointer

template<class T>
using mi::base::Std_allocator<T>::pointer = T*

Pointer type.

 reference

template<class T>
using mi::base::Std_allocator<T>::reference = T&

Reference type.

 size_type

template<class T>
using mi::base::Std_allocator<T>::size_type = std::size_t

Size type.

 value_type

template<class T>
using mi::base::Std_allocator<T>::value_type = T

Value type allocated by this allocator.

Function Documentation

 address() [1/2]

template<class T>
const_pointer mi::base::Std_allocator<T>::address ( const_reference  x) const
inline

Returns const address of object x allocated through this allocator.

 address() [2/2]

template<class T>
pointer mi::base::Std_allocator<T>::address ( reference  x) const
inline

Returns address of object x allocated through this allocator.

 allocate()

template<class T>
T * mi::base::Std_allocator<T>::allocate ( size_type  n,
const void *  = nullptr 
)
inlinenoexcept

Allocate uninitialized dynamic memory for n elements of type T.

Returns
The pointer to the allocated memory. Can be nullptr if the underlying IAllocator implementation fails to allocate the memory.

 construct()

template<class T>
void mi::base::Std_allocator<T>::construct ( pointer  p,
const_reference  value 
)
inline

Calls the copy constructor of T on the location p with the argument value.

 deallocate()

template<class T>
void mi::base::Std_allocator<T>::deallocate ( pointer  p,
size_type   
)
inline

Frees uninitialized dynamic memory at location p that has previously been allocated with allocate().

Parameters
pthe memory to be freed. If p is equal to nullptr, no operation is performed. However, note that according to

 destroy()

template<class T>
void mi::base::Std_allocator<T>::destroy ( pointer  p)
inline

Calls the destructor of T on the location p.

 free() [1/2]

void mi::base::Default_allocator::free ( void *  memory)
inlineoverridevirtual

Releases the given memory block.

Implements mi::base::IAllocator::free through a global operator delete call.

Parameters
memoryA memory block previously allocated by a call to malloc(). If memory is nullptr, no operation is performed.

Implements mi::base::IAllocator.

 free() [2/2]

virtual void mi::base::IAllocator::free ( void *  memory)
pure virtual

Releases the given memory block.

This function can be called at any time from any thread, including concurrent calls from several threads at the same time.

Parameters
memoryA memory block previously allocated by a call to malloc(). If memory is nullptr, no operation is performed.

Implemented in mi::base::Default_allocator, and mi::neuraylib::IAllocator.

 get_allocator()

template<class T>
IAllocator * mi::base::Std_allocator<T>::get_allocator ( ) const
inline

Returns the interface of the underlying allocator.

 get_instance()

static IAllocator * mi::base::Default_allocator::get_instance ( )
inlinestatic

Returns the single instance of the default allocator.

 malloc() [1/2]

void * mi::base::Default_allocator::malloc ( Size  size)
inlineoverridevirtual

Allocates a memory block of the given size.

Implements mi::base::IAllocator::malloc through a global non-throwing operator new call.

Parameters
sizeThe requested size of memory in bytes. It may be zero.
Returns
The allocated memory block.

Implements mi::base::IAllocator.

 malloc() [2/2]

virtual void * mi::base::IAllocator::malloc ( Size  size)
pure virtual

Allocates a memory block of the given size.

The memory must be aligned to an address which can accommodate any type of object on the current platform.

An allocation of zero bytes returns a valid non-null pointer which must be freed in the end. However, dereferencing this pointer gives undefined behavior.

This function can be called at any time from any thread, including concurrent calls from several threads at the same time.

If the requested memory is not available this function returns nullptr. Some products give the stronger guarantee that allocation can never fail. (They can do this, for example, by flushing parts or in its extreme, stop executing.) See the API documentation of the specific products for specific allocator interfaces or allocator documentation.

Parameters
sizeThe requested size of memory in bytes. It may be zero.
Returns
The allocated memory block.

Implemented in mi::base::Default_allocator, and mi::neuraylib::IAllocator.

 max_size()

template<class T>
size_type mi::base::Std_allocator<T>::max_size ( ) const
inlinenoexcept

Returns the maximum number of elements of type T that can be allocated using this allocator.

 operator!=()

template<class T>
template<class T2>
bool mi::base::Std_allocator<T>::operator!= ( Std_allocator<T2>  other) const
inlinenoexcept

Inequality comparison.

Returns false if the underlying IAllocator interface implementations are the same.

 operator==()

template<class T>
template<class T2>
bool mi::base::Std_allocator<T>::operator== ( Std_allocator<T2>  other) const
inlinenoexcept

Equality comparison.

Returns true if the underlying IAllocator interface implementations are the same, because then these allocators can be used interchangeably for allocation and deallocation.

 Std_allocator() [1/3]

template<class T>
mi::base::Std_allocator<T>::Std_allocator ( )
inlinenoexcept

Default constructor.

Uses mi::base::Default_allocator.

 Std_allocator() [2/3]

template<class T>
mi::base::Std_allocator<T>::Std_allocator ( base::IAllocator allocator)
inlinenoexcept

Constructor.

Constructor from an mi::base::IAllocator interface.

Parameters
allocatorAn implementation of the mi::base::IAllocator interface. Can be nullptr in which case the mi::base::Default_allocator will be used.

 Std_allocator() [3/3]

template<class T>
template<class T1>
mi::base::Std_allocator<T>::Std_allocator ( const Std_allocator<T1> &  other)
inlinenoexcept

Copying constructor template for alike allocators of different value type.