Browse Source

added uiGetAllocSize()

pull/1/head
Leonard Ritter 10 years ago
parent
commit
57110c60af
2 changed files with 20 additions and 6 deletions
  1. +7
    -0
      example.cpp
  2. +13
    -6
      oui.h

+ 7
- 0
example.cpp View File

@@ -1220,6 +1220,9 @@ int main()
double c = 0.0; double c = 0.0;
int total = 0; int total = 0;


int peak_items = 0;
unsigned int peak_alloc = 0;

while (!glfwWindowShouldClose(window)) while (!glfwWindowShouldClose(window))
{ {
double mx, my; double mx, my;
@@ -1242,6 +1245,8 @@ int main()
nvgBeginFrame(_vg, winWidth, winHeight, pxRatio); nvgBeginFrame(_vg, winWidth, winHeight, pxRatio);


draw(_vg, winWidth, winHeight); draw(_vg, winWidth, winHeight);
peak_items = (peak_items > uiGetItemCount())?peak_items:uiGetItemCount();
peak_alloc = (peak_alloc > uiGetAllocSize())?peak_alloc:uiGetAllocSize();


nvgEndFrame(_vg); nvgEndFrame(_vg);
double t2 = glfwGetTime(); double t2 = glfwGetTime();
@@ -1256,6 +1261,8 @@ int main()
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();
} }
printf("Peak item count: %i (%u bytes)\nPeak allocated handles: %u bytes\n",
peak_items, peak_items * sizeof(UIitem), peak_alloc);


uiDestroyContext(uictx); uiDestroyContext(uictx);




+ 13
- 6
oui.h View File

@@ -565,7 +565,7 @@ OUI_EXPORT void uiSetHandle(int item, void *handle);
// as the handle to the item. // as the handle to the item.
// The memory of the pointer is managed by the UI context and released // The memory of the pointer is managed by the UI context and released
// upon the next call to uiClear() // 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. // set the global handler callback for interactive items.
// the handler will be called for each item whose event flags are set using // 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 // return the total number of allocated items
OUI_EXPORT int uiGetItemCount(); 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 // return the current state of the item. This state is only valid after
// a call to uiProcess(). // a call to uiProcess().
// The returned value is one of UI_COLD, UI_HOT, UI_ACTIVE, UI_FROZEN. // The returned value is one of UI_COLD, UI_HOT, UI_ACTIVE, UI_FROZEN.
@@ -828,8 +831,8 @@ struct UIcontext {
int clicks; int clicks;


int count; int count;
int datasize;
int eventcount; int eventcount;
unsigned int datasize;


UIitem *items; UIitem *items;
unsigned char *data; unsigned char *data;
@@ -988,12 +991,16 @@ unsigned int uiGetModifier() {
return ui_context->active_modifier; return ui_context->active_modifier;
} }


// return the total number of allocated items
OUI_EXPORT int uiGetItemCount() {
int uiGetItemCount() {
assert(ui_context); assert(ui_context);
return ui_context->count; return ui_context->count;
} }


unsigned int uiGetAllocSize() {
assert(ui_context);
return ui_context->datasize;
}

UIitem *uiItemPtr(int item) { UIitem *uiItemPtr(int item) {
assert(ui_context && (item >= 0) && (item < ui_context->count)); assert(ui_context && (item >= 0) && (item < ui_context->count));
return ui_context->items + item; return ui_context->items + item;
@@ -1043,7 +1050,7 @@ void uiClearState() {


int uiItem() { int uiItem() {
assert(ui_context); 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++; int idx = ui_context->count++;
UIitem *item = uiItemPtr(idx); UIitem *item = uiItemPtr(idx);
memset(item, 0, sizeof(UIitem)); memset(item, 0, sizeof(UIitem));
@@ -1500,7 +1507,7 @@ int uiNextSibling(int item) {
return uiItemPtr(item)->nextitem; return uiItemPtr(item)->nextitem;
} }


void *uiAllocHandle(int item, int size) {
void *uiAllocHandle(int item, unsigned int size) {
assert((size > 0) && (size < UI_MAX_DATASIZE)); assert((size > 0) && (size < UI_MAX_DATASIZE));
UIitem *pitem = uiItemPtr(item); UIitem *pitem = uiItemPtr(item);
assert(pitem->handle == NULL); assert(pitem->handle == NULL);


Loading…
Cancel
Save