Vuo
2.4.1
|
Functions to manage memory for heap-allocated port and node instance data.
Macros | |
#define | VuoRegister(heapPointer, deallocate) |
Registers heapPointer to be reference-counted and stores its deallocate function (unless heapPointer is null or is already being reference-counted). More... | |
#define | VuoRegisterSingleton(heapPointer) |
Registers heapPointer as a singleton, meaning that VuoRetain and VuoRelease will have no effect on it (and will not issue warnings). More... | |
#define | VuoLocal(heapPointer) |
Immediately retains heapPointer , and automatically releases it at the end of the local scope. More... | |
Typedefs | |
typedef void(* | DeallocateFunctionType) (void *) |
A type for destructor functions, such as free(void *) , which are used to deallocate reference-counted memory when it's no longer in use. More... | |
Functions | |
int | VuoRetain (const void *heapPointer) |
Increments the reference count for heapPointer (unless heapPointer is not being reference-counted). More... | |
int | VuoRelease (const void *heapPointer) |
Decrements the reference count for heapPointer (unless heapPointer is not being reference-counted). More... | |
#define VuoLocal | ( | heapPointer | ) |
Immediately retains heapPointer
, and automatically releases it at the end of the local scope.
When working with local reference-counted variables, typically you make the object, retain it, work with it, then release it:
But if this code has multiple exit points (for example, returning early upon encountering a runtime error), it can be tricky to remember to release at all the right times:
Instead, you can use this macro to simplify local reference-counting:
#define VuoRegister | ( | heapPointer, | |
deallocate | |||
) |
Registers heapPointer to be reference-counted and stores its deallocate function (unless heapPointer is null or is already being reference-counted).
heapPointer | A pointer to allocated memory on the heap. |
deallocate | The function to be used to deallocate the memory when the reference count gets back to its original value of 0. |
#define VuoRegisterSingleton | ( | heapPointer | ) |
Registers heapPointer as a singleton, meaning that VuoRetain and VuoRelease will have no effect on it (and will not issue warnings).
heapPointer | A pointer to allocated memory on the heap. |
typedef void(* DeallocateFunctionType) (void *) |
A type for destructor functions, such as free(void *)
, which are used to deallocate reference-counted memory when it's no longer in use.
These destructor functions are responsible for deallocating both the memory pointed to by void *
, as well as (if it's a structure) releasing any memory pointed to within it.
int VuoRelease | ( | const void * | heapPointer | ) |
Decrements the reference count for heapPointer (unless heapPointer is not being reference-counted).
If the reference count becomes 0, heapPointer is deallocated and is no longer reference-counted.
heapPointer | A pointer to allocated memory on the heap. |
Definition at line 477 of file VuoHeap.cc.
int VuoRetain | ( | const void * | heapPointer | ) |
Increments the reference count for heapPointer (unless heapPointer is not being reference-counted).
heapPointer | A pointer to allocated memory on the heap. |
Definition at line 400 of file VuoHeap.cc.