Removed the dependency on realloc functionality #117 + fixed one alloc in NewFrame()

This commit is contained in:
ocornut 2015-02-01 14:39:13 +00:00
parent 56bf9ea067
commit bde3f6b90d
2 changed files with 13 additions and 12 deletions

View File

@ -128,6 +128,7 @@
Occasionally introducing changes that are breaking the API. The breakage are generally minor and easy to fix.
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.
- 2015/02/01 (1.31) - removed IO.MemReallocFn (unused)
- 2015/01/19 (1.30) - renamed ImGuiStorage::GetIntPtr()/GetFloatPtr() to GetIntRef()/GetIntRef() because Ptr was conflicting with actual pointer storage functions.
- 2015/01/11 (1.30) - big font/image API change! now loads TTF file. allow for multiple fonts. no need for a PNG loader.
(1.30) - removed GetDefaultFontData(). uses io.Fonts->GetTextureData*() API to retrieve uncompressed pixels.
@ -537,7 +538,6 @@ ImGuiIO::ImGuiIO()
// User functions
RenderDrawListsFn = NULL;
MemAllocFn = malloc;
MemReallocFn = realloc;
MemFreeFn = free;
GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations
SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
@ -1484,11 +1484,6 @@ void ImGui::MemFree(void* ptr)
{
return GImGui.IO.MemFreeFn(ptr);
}
void* ImGui::MemRealloc(void* ptr, size_t sz)
{
return GImGui.IO.MemReallocFn(ptr, sz);
}
static ImGuiIniData* FindWindowSettings(const char* name)
{
@ -1754,7 +1749,7 @@ void ImGui::NewFrame()
// No window should be open at the beginning of the frame.
// But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
g.CurrentWindowStack.clear();
g.CurrentWindowStack.resize(0);
// Create implicit window - we will only render it if the user has added something to it.
ImGui::Begin("Debug", NULL, ImVec2(400,400));

16
imgui.h
View File

@ -69,10 +69,9 @@ struct ImVec4
namespace ImGui
{
// Proxy functions to access the MemAllocFn/MemFreeFn/MemReallocFn pointers in ImGui::GetIO(). The only reason they exist here is to allow ImVector<> to compile inline.
// Proxy functions to access the MemAllocFn/MemFreeFn pointers in ImGui::GetIO(). The only reason they exist here is to allow ImVector<> to compile inline.
IMGUI_API void* MemAlloc(size_t sz);
IMGUI_API void MemFree(void* ptr);
IMGUI_API void* MemRealloc(void* ptr, size_t sz);
}
// std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
@ -115,8 +114,16 @@ public:
inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size-1]; }
inline void swap(ImVector<T>& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; }
inline void reserve(size_t new_capacity) { Data = (value_type*)ImGui::MemRealloc(Data, new_capacity * sizeof(value_type)); Capacity = new_capacity; }
inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; }
inline void reserve(size_t new_capacity)
{
if (new_capacity <= Capacity) return;
T* new_data = (value_type*)ImGui::MemAlloc(new_capacity * sizeof(value_type));
memcpy(new_data, Data, Size * sizeof(value_type));
ImGui::MemFree(Data);
Data = new_data;
Capacity = new_capacity;
}
inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; }
inline void pop_back() { IM_ASSERT(Size > 0); Size--; }
@ -523,9 +530,8 @@ struct ImGuiIO
const char* (*GetClipboardTextFn)();
void (*SetClipboardTextFn)(const char* text);
// Optional: override memory allocations (default to posix malloc/realloc/free). MemFreeFn() may be called with a NULL pointer.
// Optional: override memory allocations (default to posix malloc/free). MemFreeFn() may be called with a NULL pointer.
void* (*MemAllocFn)(size_t sz);
void* (*MemReallocFn)(void* ptr, size_t sz);
void (*MemFreeFn)(void* ptr);
// Optional: notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese inputs in Windows)