NVIDIA Iray: Base API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mi::base::IAllocator Class Referenceabstract

The IAllocator interface class supports allocating and releasing memory dynamically. More...

Inheritance diagram for mi::base::IAllocator:
Inheritance graph
[legend]

Public Types

typedef Interface_declare< id1,
id2, id3, id4, id5, id6, id7,
id8, id9, id10, id11,
IInterface
Self
  Own type. More...
 
typedef Uuid_t< id1, id2, id3,
id4, id5, id6, id7, id8, id9,
id10, id11 > 
IID
  Declares the interface ID (IID) of this interface. More...
 

Public Member Functions

virtual void *  malloc (Size size)=0
  Allocates a memory block of the given size. More...
 
virtual void  free (void *memory)=0
  Releases the given memory block. More...
 
virtual Uint32  retain () const =0
  Increments the reference count. More...
 
virtual Uint32  release () const =0
  Decrements the reference count. More...
 
virtual const IInterface get_interface (const Uuid &interface_id) const =0
  Acquires a const interface from another. More...
 
template<class T >
const T *  get_interface () const
  Acquires a const interface from another. More...
 
virtual IInterface get_interface (const Uuid &interface_id)=0
  Acquires a mutable interface from another. More...
 
template<class T >
T *  get_interface ()
  Acquires a mutable interface from another. More...
 
virtual Uuid  get_iid () const =0
  Returns the interface ID of the most derived interface. More...
 

Static Public Member Functions

static bool  compare_iid (const Uuid &iid)
  Compares the interface ID iid against the interface ID of this interface and of its ancestors. More...
 

Detailed Description

The IAllocator interface class supports allocating and releasing memory dynamically.

Different APIs allow to be configured with your own implementation of an allocator to override their internal implementation.

Include File:
#include <mi/base/iallocator.h>

Member Typedef Documentation

typedef Uuid_t<id1,id2,id3,id4,id5,id6,id7,id8,id9,id10,id11> mi::base::Interface_declare< id1, id2, id3, id4, id5, id6, id7, id8, id9, id10, id11, IInterface >::IID
inherited

Declares the interface ID (IID) of this interface.

typedef Interface_declare<id1,id2,id3,id4,id5,id6,id7,id8,id9,id10,id11,IInterface > mi::base::Interface_declare< id1, id2, id3, id4, id5, id6, id7, id8, id9, id10, id11, IInterface >::Self
inherited

Own type.

Member Function Documentation

static bool mi::base::Interface_declare< id1, id2, id3, id4, id5, id6, id7, id8, id9, id10, id11, IInterface >::compare_iid ( const Uuid iid)
inlinestaticinherited

Compares the interface ID iid against the interface ID of this interface and of its ancestors.

Returns
true if iid == IID() or is equal to one of the interface IDs of its ancestors, and false otherwise.
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
memory A memory block previously allocated by a call to malloc(). If memory is NULL, no operation is performed.

Implemented in mi::base::Default_allocator.

virtual Uuid mi::base::IInterface::get_iid ( ) const
pure virtualinherited

Returns the interface ID of the most derived interface.

Implemented in mi::base::Interface_implement_singleton< IAllocator >.

virtual const IInterface* mi::base::IInterface::get_interface ( const Uuid interface_id) const
pure virtualinherited

Acquires a const interface from another.

If this interface supports the interface with the passed interface_id, then the method returns a non-NULL const mi::base::IInterface* that can be casted via static_cast to an interface pointer of the interface type corresponding to the passed interface_id. Otherwise, the method returns NULL.

In the case of a non-NULL return value, the caller receives ownership of the new interface pointer, whose reference count has been retained once. The caller must release the returned interface pointer at the end to prevent a memory leak.

Parameters
interface_id Interface ID of the interface to acquire.

Implemented in mi::base::Interface_implement_singleton< IAllocator >.

template<class T >
const T* mi::base::IInterface::get_interface ( ) const
inlineinherited

Acquires a const interface from another.

If this interface supports the interface T, then the method returns a non-NULL const pointer to the interface T. Otherwise, the method returns NULL.

In the case of a non-NULL return value, the caller receives ownership of the new interface pointer, whose reference count has been retained once. The caller must release the returned interface pointer at the end to prevent a memory leak.

This templated member function is a wrapper of the non-template variant for the user's convenience. It eliminates the need to apply static_cast to the returned pointer, since the return type already is a const pointer to the type T specified as template parameter.

Template Parameters
T The requested interface type.
virtual IInterface* mi::base::IInterface::get_interface ( const Uuid interface_id)
pure virtualinherited

Acquires a mutable interface from another.

If this interface supports the interface with the passed interface_id, then the methods returns a non-NULL mi::base::IInterface* that can be casted via static_cast to an interface pointer of the interface type corresponding to the passed interface_id. Otherwise, the method returns NULL.

In the case of a non-NULL return value, the caller receives ownership of the new interface pointer, whose reference count has been retained once. The caller must release the returned interface pointer at the end to prevent a memory leak.

Parameters
interface_id Interface ID of the interface to acquire.

Implemented in mi::base::Interface_implement_singleton< IAllocator >.

template<class T >
T* mi::base::IInterface::get_interface ( )
inlineinherited

Acquires a mutable interface from another.

If this interface supports the interface T, then the method returns a non-NULL pointer to the interface T. Otherwise, the method returns NULL.

In the case of a non-NULL return value, the caller receives ownership of the new interface pointer, whose reference count has been retained once. The caller must release the returned interface pointer at the end to prevent a memory leak.

This templated member function is a wrapper of the non-template variant for the user's convenience. It eliminates the need to apply static_cast to the returned pointer, since the return type already is a pointer to the type T specified as template parameter.

Template Parameters
T The requested interface type.
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 NULL. 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
size The requested size of memory in bytes. It may be zero.
Returns
The allocated memory block.

Implemented in mi::base::Default_allocator.

virtual Uint32 mi::base::IInterface::release ( ) const
pure virtualinherited

Decrements the reference count.

Decrements the reference count of the object referenced through this interface and returns the new reference count. If the reference count dropped to zero, the object will be deleted. The operation is thread-safe.

Returns
The new, decremented reference count.

Implemented in mi::base::Interface_implement_singleton< IAllocator >.

virtual Uint32 mi::base::IInterface::retain ( ) const
pure virtualinherited

Increments the reference count.

Increments the reference count of the object referenced through this interface and returns the new reference count. The operation is thread-safe.

Returns
The new, incremented reference count.

Implemented in mi::base::Interface_implement_singleton< IAllocator >.