From 57110c60afe6c36eb9c3fb8f666c11e4d98bdb0f Mon Sep 17 00:00:00 2001 From: Leonard Ritter Date: Thu, 25 Sep 2014 03:20:10 +0200 Subject: [PATCH] added uiGetAllocSize() --- example.cpp | 7 +++++++ oui.h | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/example.cpp b/example.cpp index a8ffdf3..f3b82e6 100644 --- a/example.cpp +++ b/example.cpp @@ -1220,6 +1220,9 @@ int main() double c = 0.0; int total = 0; + int peak_items = 0; + unsigned int peak_alloc = 0; + while (!glfwWindowShouldClose(window)) { double mx, my; @@ -1242,6 +1245,8 @@ int main() nvgBeginFrame(_vg, winWidth, winHeight, pxRatio); draw(_vg, winWidth, winHeight); + peak_items = (peak_items > uiGetItemCount())?peak_items:uiGetItemCount(); + peak_alloc = (peak_alloc > uiGetAllocSize())?peak_alloc:uiGetAllocSize(); nvgEndFrame(_vg); double t2 = glfwGetTime(); @@ -1256,6 +1261,8 @@ int main() glfwSwapBuffers(window); glfwPollEvents(); } + printf("Peak item count: %i (%u bytes)\nPeak allocated handles: %u bytes\n", + peak_items, peak_items * sizeof(UIitem), peak_alloc); uiDestroyContext(uictx); diff --git a/oui.h b/oui.h index c9ef8ba..9b9440e 100644 --- a/oui.h +++ b/oui.h @@ -565,7 +565,7 @@ OUI_EXPORT void uiSetHandle(int item, void *handle); // as the handle to the item. // The memory of the pointer is managed by the UI context and released // upon the next call to uiClear() -OUI_EXPORT void *uiAllocHandle(int item, int size); +OUI_EXPORT void *uiAllocHandle(int item, unsigned int size); // set the global handler callback for interactive items. // the handler will be called for each item whose event flags are set using @@ -630,6 +630,9 @@ OUI_EXPORT int uiNextSibling(int item); // return the total number of allocated items OUI_EXPORT int uiGetItemCount(); +// return the total bytes that have been allocated by uiAllocHandle() +OUI_EXPORT unsigned int uiGetAllocSize(); + // return the current state of the item. This state is only valid after // a call to uiProcess(). // The returned value is one of UI_COLD, UI_HOT, UI_ACTIVE, UI_FROZEN. @@ -828,8 +831,8 @@ struct UIcontext { int clicks; int count; - int datasize; int eventcount; + unsigned int datasize; UIitem *items; unsigned char *data; @@ -988,12 +991,16 @@ unsigned int uiGetModifier() { return ui_context->active_modifier; } -// return the total number of allocated items -OUI_EXPORT int uiGetItemCount() { +int uiGetItemCount() { assert(ui_context); return ui_context->count; } +unsigned int uiGetAllocSize() { + assert(ui_context); + return ui_context->datasize; +} + UIitem *uiItemPtr(int item) { assert(ui_context && (item >= 0) && (item < ui_context->count)); return ui_context->items + item; @@ -1043,7 +1050,7 @@ void uiClearState() { int uiItem() { assert(ui_context); - assert(ui_context->count < ui_context->item_capacity); + assert(ui_context->count < (int)ui_context->item_capacity); int idx = ui_context->count++; UIitem *item = uiItemPtr(idx); memset(item, 0, sizeof(UIitem)); @@ -1500,7 +1507,7 @@ int uiNextSibling(int item) { return uiItemPtr(item)->nextitem; } -void *uiAllocHandle(int item, int size) { +void *uiAllocHandle(int item, unsigned int size) { assert((size > 0) && (size < UI_MAX_DATASIZE)); UIitem *pitem = uiItemPtr(item); assert(pitem->handle == NULL);