Functions
Memory Allocation API

Memory allocation and deallocation. More...

Functions

AI_API void * AiMalloc (size_t size)
 Arnold malloc() wrapper. More...
 
AI_API void * AiRealloc (void *addr, size_t size)
 Arnold realloc() wrapper. More...
 
AI_API void AiFree (void *addr)
 Arnold free() wrapper. More...
 
AI_API void AiAddMemUsage (int64_t size, const AtString category)
 Track allocated memory by named category. More...
 
AI_API size_t AiMallocUsableSize (const void *addr)
 Returns how much memory was actually allocated for this pointer by AiMalloc.
 

Detailed Description

Memory allocation and deallocation.


Function Documentation

◆ AiMalloc()

AI_API void * AiMalloc ( size_t  size)

Arnold malloc() wrapper.

Use this function just as you would use malloc() to request a block of memory. If the size requested is 0, then return NULL. If the internal call to malloc() returns NULL, which means there is not enough available memory for a block of that size, this function logs a warning message. This is a useful debugging tip that wouldn't be possible with a regular call to malloc().

ptr = AiMalloc(1024);

Parameters
sizenumber of bytes to allocate
Returns
if succesful, pointer to a newly allocated memory block, NULL otherwise
See also
AiMalloc, AiFree, AiShaderGlobalsQuickAlloc

◆ AiRealloc()

AI_API void * AiRealloc ( void *  addr,
size_t  size 
)

Arnold realloc() wrapper.

Checks for NULL and logs a warning message. If the requested size is 0, then the address is freed instead.

Parameters
addrthe address of the memory block to resize
sizenumber of bytes to allocate
Returns
pointer to a newly allocated memory block or NULL
See also
AiRealloc

◆ AiFree()

AI_API void AiFree ( void *  addr)

Arnold free() wrapper.

Releases allocated memory from AiMalloc() and AiRealloc(). Works just like free().

Parameters
addrthe address of the memory block to release

◆ AiAddMemUsage()

AI_API void AiAddMemUsage ( int64_t  size,
const AtString  category 
)

Track allocated memory by named category.

You can track amounts of memory in your code you allocate (with positive values) and deallocate (with negative values). The totals will be displayed at the end of each AiRender() call in the logged memory stats. This is only valid to call in between AiBegin() and AiEnd(), but it can and should be used inside of any plugins as well as in session API usage.

Warning
If you call this from threads your own code spawns, this memory tracking will be slower than if it is called from within Arnold threads.
Parameters
sizeThe size of the allocation (if positive) or deallocation (if negative)
categoryName of the category for the allocation/deallocation

© 2023 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com