Skip to content

Commit

Permalink
Context: Renamed SetMemoryAllocators() to SetAllocatorFunctions(). Tw…
Browse files Browse the repository at this point in the history
…eaked comments. (#1565, #586, #992, #1007, #1558)
  • Loading branch information
ocornut committed Jan 21, 2018
1 parent e45d7a7 commit 7e4d28a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
Also read releases logs https://github.com/ocornut/imgui/releases for more details.

- 2018/01/20 (1.XX) - removed allocator parameters from CreateContext(), they are now setup with SetMemoryAllocators() and shared by all contexts.
- 2018/01/20 (1.XX) - removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions() and shared by all contexts.
- 2018/01/11 (1.54) - obsoleted IsAnyWindowHovered() in favor of IsWindowHovered(ImGuiHoveredFlags_AnyWindow). Kept redirection function (will obsolete).
- 2018/01/11 (1.54) - obsoleted IsAnyWindowFocused() in favor of IsWindowFocused(ImGuiFocusedFlags_AnyWindow). Kept redirection function (will obsolete).
- 2018/01/03 (1.54) - renamed ImGuiSizeConstraintCallback to ImGuiSizeCallback, ImGuiSizeConstraintCallbackData to ImGuiSizeCallbackData.
Expand Down Expand Up @@ -710,8 +710,8 @@ static ImGuiContext GImDefaultContext;
ImGuiContext* GImGui = &GImDefaultContext;
#endif

// Memory Allocator Functions. Use SetMemoryAllocators() to change them.
// If you use DLL hotreloading you might need to call SetMemoryAllocators() after reloading code from this file.
// Memory Allocator functions. Use SetAllocatorFunctions() to change them.
// If you use DLL hotreloading you might need to call SetAllocatorFunctions() after reloading code from this file.
// Otherwise, you probably don't want to modify them mid-program, and if you use global/static e.g. ImVector<> instances you may need to keep them accessible during program destruction.
#ifndef IMGUI_DISABLE_DEFAULT_ALLOCATORS
static void* MallocWrapper(size_t size, void* user_data) { (void)user_data; return malloc(size); }
Expand All @@ -724,7 +724,7 @@ static void FreeWrapper(void* ptr, void* user_data) { (void)user_data;
static void* (*GImAllocatorAllocFunc)(size_t size, void* user_data) = MallocWrapper;
static void (*GImAllocatorFreeFunc)(void* ptr, void* user_data) = FreeWrapper;
static void* GImAllocatorUserData = NULL;
static size_t GImAllocatorActiveCount = 0;
static size_t GImAllocatorActiveAllocationsCount = 0;

//-----------------------------------------------------------------------------
// User facing structures
Expand Down Expand Up @@ -2188,13 +2188,13 @@ float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)

void* ImGui::MemAlloc(size_t sz)
{
GImAllocatorActiveCount++;
GImAllocatorActiveAllocationsCount++;
return GImAllocatorAllocFunc(sz, GImAllocatorUserData);
}

void ImGui::MemFree(void* ptr)
{
if (ptr) GImAllocatorActiveCount--;
if (ptr) GImAllocatorActiveAllocationsCount--;
return GImAllocatorFreeFunc(ptr, GImAllocatorUserData);
}

Expand Down Expand Up @@ -2230,10 +2230,10 @@ void ImGui::SetCurrentContext(ImGuiContext* ctx)
#endif
}

void ImGui::SetMemoryAllocators(void* (*alloc_fn)(size_t sz, void* user_data), void(*free_fn)(void* ptr, void* user_data), void* user_data)
void ImGui::SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void(*free_func)(void* ptr, void* user_data), void* user_data)
{
GImAllocatorAllocFunc = alloc_fn;
GImAllocatorFreeFunc = free_fn;
GImAllocatorAllocFunc = alloc_func;
GImAllocatorFreeFunc = free_func;
GImAllocatorUserData = user_data;
}

Expand Down Expand Up @@ -11684,7 +11684,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
ImGui::Text("Dear ImGui %s", ImGui::GetVersion());
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::Text("%d vertices, %d indices (%d triangles)", ImGui::GetIO().MetricsRenderVertices, ImGui::GetIO().MetricsRenderIndices, ImGui::GetIO().MetricsRenderIndices / 3);
ImGui::Text("%d allocations", GImAllocatorActiveCount);
ImGui::Text("%d allocations", GImAllocatorActiveAllocationsCount);
static bool show_clip_rects = true;
ImGui::Checkbox("Show clipping rectangles when hovering an ImDrawCmd", &show_clip_rects);
ImGui::Separator();
Expand Down
6 changes: 3 additions & 3 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,9 @@ namespace ImGui
IMGUI_API void CaptureKeyboardFromApp(bool capture = true); // manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application handle). e.g. force capture keyboard when your widget is being hovered.
IMGUI_API void CaptureMouseFromApp(bool capture = true); // manually override io.WantCaptureMouse flag next frame (said flag is entirely left for your application handle).

// Helpers functions to access functions pointers in ImGui::GetIO()
IMGUI_API void* MemAlloc(size_t sz);
// Helpers functions to access memory allocators and clipboard functions.
IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void(*free_func)(void* ptr, void* user_data), void* user_data = NULL);
IMGUI_API void* MemAlloc(size_t size);
IMGUI_API void MemFree(void* ptr);
IMGUI_API const char* GetClipboardText();
IMGUI_API void SetClipboardText(const char* text);
Expand All @@ -513,7 +514,6 @@ namespace ImGui
// All contexts share a same ImFontAtlas by default. If you want different font atlas, you can new() them and overwrite the GetIO().Fonts variable of an ImGui context.
// All those functions are not reliant on the current context.
IMGUI_API const char* GetVersion();
IMGUI_API void SetMemoryAllocators(void* (*alloc_fn)(size_t sz, void* user_data), void(*free_fn)(void* ptr, void* user_data), void* user_data = NULL);
IMGUI_API ImGuiContext* CreateContext();
IMGUI_API void DestroyContext(ImGuiContext* ctx);
IMGUI_API ImGuiContext* GetCurrentContext();
Expand Down

0 comments on commit 7e4d28a

Please sign in to comment.