neuray API Programmer's Manual

mi::neuraylib::IAllocator Class Reference

[MainneurayAdjectiveName Interface and C access function]

Description

The Allocator interface class supports allocating and releasing memory dynamically and querying the amount of extra memory used in the integrating application. You can provide your own allocator object implementing this interface at initialization time of the to have the neuray API use your memory management.

Public Member Functions

virtual void free( void* memory) =0
Releases the given memory block. More...
virtual Size get_used_extra_memory() =0
This function is used by to inquire the amount of extra memory currently in use in the application. More...
virtual void* malloc( Size size) =0
Allocates a memory block of the given size. More...

Member Functions

virtual void mi::​neuraylib::​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.
virtual Size mi::​neuraylib::​IAllocator::get_used_extra_memory() [pure virtual]

This function is used by to inquire the amount of extra memory currently in use in the application. This function may be called frequently and must be implemented efficiently.

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

virtual void* mi::​neuraylib::​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 must return NULL. In this case will try to reduce the memory it uses and retry the allocation. If allocation still fails will give up. In this case can not be used anymore and must be shut down. will try to release as much memory as possible but it can not be guaranteed that all memory is returned. It is not possible to restart the library after a failure without restarting the process.

Plugins for the neuray API will get an allocator implementation that uses memory management to give the stronger guarantee that allocation can never fail.

Parameters

size
The requested size of memory in bytes. It may be zero.

Returns

The allocated memory block.