VuoHeap implementation.
Definition in file VuoHeap.cc.
Go to the source code of this file.
Classes | |
struct | VuoHeapEntry |
An entry in the reference-counting table. More... | |
Functions | |
void | sendErrorWrapper (const char *message) |
Calls the vuoSendError() function defined in the runtime (without introducing a direct dependency on the runtime). More... | |
static void | VuoHeap_lock (void) |
Waits for referenceCountsSemaphore to become available. More... | |
static void | VuoHeap_unlock (void) |
Releases referenceCountsSemaphore . More... | |
bool | VuoHeap_isPointerReadable (const void *pointer) |
Returns true if pointer points to a memory page that's been allocated (and therefore might be a valid pointer to 1 or more bytes of data). More... | |
static void | VuoHeap_makeSafePointerSummary (char *summary, const void *pointer) |
If pointer refers to allocated memory, copies its first 16 printable characters into summary , followed by char 0. More... | |
static char * | VuoHeap_makeDescription (VuoHeapEntry e) |
Returns a description of the specified heapPointer: the file, line, and function where VuoRegister() was called, and the variable name. More... | |
static void | __attribute__ ((constructor(101))) VuoHeap_init() |
Initializes the reference-counting system. More... | |
void | VuoHeap_report (void) |
Sends a telemetry error with information about any objects remaining in the reference counting table. More... | |
int | VuoRegisterF (const void *heapPointer, DeallocateFunctionType deallocate, const char *file, unsigned int linenumber, const char *func, const char *pointerName) |
Instead of this function, you probably want to use VuoRegister(). More... | |
int | VuoRegisterSingletonF (const void *heapPointer, const char *file, unsigned int linenumber, const char *func, const char *pointerName) |
Instead of this function, you probably want to use VuoRegisterSingleton(). More... | |
int | VuoRetainF (const void *heapPointer, const char *file, unsigned int linenumber, const char *func) |
Wrapper for VuoRetain. More... | |
int | VuoRetain (const void *heapPointer) |
int | VuoReleaseF (const void *heapPointer, const char *file, unsigned int linenumber, const char *func) |
Wrapper for VuoRelease. More... | |
int | VuoRelease (const void *heapPointer) |
const char * | VuoHeap_getDescription (const void *heapPointer) |
Returns a description of the specified heapPointer: the file, line, and function where VuoRegister() was called, and the variable name. More... | |
void | VuoHeap_addTrace (const void *heapPointer) |
Pass a pointer to this function to log all its subsequent retains and releases. More... | |
Variables | |
static set< const void * > * | VuoHeap_trace |
Heap pointers to trace. More... | |
static map< const void *, VuoHeapEntry > * | referenceCounts |
The reference count for each pointer. More... | |
static set< const void * > * | singletons |
Known singleton pointers. More... | |
static unsigned int * | referenceCountsSemaphore = 0 |
Synchronizes access to referenceCounts. More... | |
struct VuoHeapEntry |
Class Members | ||
---|---|---|
DeallocateFunctionType | deallocateFunction | |
const char * | file | |
const char * | function | |
unsigned int | line | |
int | referenceCount | |
const char * | variable |
|
static |
Initializes the reference-counting system.
This function is automatically added near the beginning of the linker module's call graph.
Definition at line 182 of file VuoHeap.cc.
void sendErrorWrapper | ( | const char * | message | ) |
Calls the vuoSendError() function defined in the runtime (without introducing a direct dependency on the runtime).
Definition at line 28 of file VuoHeap.cc.
void VuoHeap_addTrace | ( | const void * | heapPointer | ) |
Pass a pointer to this function to log all its subsequent retains and releases.
This only has an effect when CMake option VUO_HEAP_TRACE
is enabled.
Definition at line 571 of file VuoHeap.cc.
const char* VuoHeap_getDescription | ( | const void * | heapPointer | ) |
Returns a description of the specified heapPointer: the file, line, and function where VuoRegister() was called, and the variable name.
The caller is responsible for freeing the returned string.
Definition at line 557 of file VuoHeap.cc.
bool VuoHeap_isPointerReadable | ( | const void * | pointer | ) |
Returns true if pointer
points to a memory page that's been allocated (and therefore might be a valid pointer to 1 or more bytes of data).
Definition at line 119 of file VuoHeap.cc.
|
inlinestatic |
Waits for referenceCountsSemaphore
to become available.
Spinlocks are faster than dispatch semaphores when under contention, especially on macOS 10.12. https://b33p.net/kosada/node/12778
Definition at line 92 of file VuoHeap.cc.
|
static |
Returns a description of the specified heapPointer: the file, line, and function where VuoRegister() was called, and the variable name.
The caller is responsible for freeing the returned string.
Definition at line 168 of file VuoHeap.cc.
|
static |
If pointer
refers to allocated memory, copies its first 16 printable characters into summary
, followed by char 0.
Definition at line 143 of file VuoHeap.cc.
void VuoHeap_report | ( | void | ) |
Sends a telemetry error with information about any objects remaining in the reference counting table.
Definition at line 220 of file VuoHeap.cc.
|
inlinestatic |
Releases referenceCountsSemaphore
.
Definition at line 107 of file VuoHeap.cc.
int VuoRegisterF | ( | const void * | heapPointer, |
DeallocateFunctionType | deallocate, | ||
const char * | file, | ||
unsigned int | linenumber, | ||
const char * | func, | ||
const char * | pointerName | ||
) |
Instead of this function, you probably want to use VuoRegister().
This function is used to implement the VuoRegister() macro.
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. |
file | The name of the file in which VuoRegister() is called. |
linenumber | The line in the file in which VuoRegister() is called. |
func | The function in which VuoRegister() is called. |
pointerName | The stringified pointer variable name. |
Definition at line 263 of file VuoHeap.cc.
int VuoRegisterSingletonF | ( | const void * | heapPointer, |
const char * | file, | ||
unsigned int | linenumber, | ||
const char * | func, | ||
const char * | pointerName | ||
) |
Instead of this function, you probably want to use VuoRegisterSingleton().
This function is used to implement the VuoRegisterSingleton() macro.
Definition at line 319 of file VuoHeap.cc.
int VuoReleaseF | ( | const void * | heapPointer, |
const char * | file, | ||
unsigned int | linenumber, | ||
const char * | func | ||
) |
Wrapper for VuoRelease.
This used to be an instrumented function, but the instrumentation was removed in Vuo 1.2 to improve performance. It's still here so that plugins compiled with Vuo 0.9 through 1.1 have a better chance of linking successfully.
Definition at line 446 of file VuoHeap.cc.
int VuoRetainF | ( | const void * | heapPointer, |
const char * | file, | ||
unsigned int | linenumber, | ||
const char * | func | ||
) |
Wrapper for VuoRetain.
This used to be an instrumented function, but the instrumentation was removed in Vuo 1.2 to improve performance. It's still here so that plugins compiled with Vuo 0.9 through 1.1 have a better chance of linking successfully.
Definition at line 376 of file VuoHeap.cc.
|
static |
The reference count for each pointer.
Definition at line 82 of file VuoHeap.cc.
|
static |
Synchronizes access to referenceCounts.
Definition at line 84 of file VuoHeap.cc.
|
static |
Known singleton pointers.
Definition at line 83 of file VuoHeap.cc.
|
static |
Heap pointers to trace.
Definition at line 23 of file VuoHeap.cc.