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. | |
Memory allocation and deallocation.
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);
size | number of bytes to allocate |
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.
addr | the address of the memory block to resize |
size | number of bytes to allocate |
AI_API void AiFree | ( | void * | addr | ) |
Arnold free()
wrapper.
Releases allocated memory from AiMalloc() and AiRealloc(). Works just like free()
.
addr | the address of the memory block to release |
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.
size | The size of the allocation (if positive) or deallocation (if negative) |
category | Name of the category for the allocation/deallocation |