Removed the dependency on realloc functionality

This commit is contained in:
Jim Tilander 2015-01-31 16:17:39 -08:00
parent 3f6091b26b
commit 98e71afa72
2 changed files with 8 additions and 11 deletions

View File

@ -537,7 +537,6 @@ ImGuiIO::ImGuiIO()
// User functions // User functions
RenderDrawListsFn = NULL; RenderDrawListsFn = NULL;
MemAllocFn = malloc; MemAllocFn = malloc;
MemReallocFn = realloc;
MemFreeFn = free; MemFreeFn = free;
GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations
SetClipboardTextFn = SetClipboardTextFn_DefaultImpl; SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
@ -1479,11 +1478,6 @@ void ImGui::MemFree(void* ptr)
{ {
return GImGui.IO.MemFreeFn(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) static ImGuiIniData* FindWindowSettings(const char* name)
{ {

13
imgui.h
View File

@ -72,7 +72,6 @@ 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/MemReallocFn 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* MemAlloc(size_t sz);
IMGUI_API void MemFree(void* ptr); 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). // 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).
@ -114,8 +113,13 @@ public:
inline value_type& back() { IM_ASSERT(Size > 0); return Data[Size-1]; } inline value_type& back() { IM_ASSERT(Size > 0); return Data[Size-1]; }
inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size-1]; } 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 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) { if( new_capacity <= Capacity )
inline void reserve(size_t new_capacity) { Data = (value_type*)ImGui::MemRealloc(Data, new_capacity * sizeof(value_type)); Capacity = new_capacity; } return;
T* NewData = (value_type*)ImGui::MemAlloc(new_capacity * sizeof(value_type));
memcpy(NewData, Data, Size * sizeof(value_type));
ImGui::MemFree(Data);
Data = NewData;
Capacity = new_capacity; }
inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; } inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; }
inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; } inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; }
@ -523,9 +527,8 @@ struct ImGuiIO
const char* (*GetClipboardTextFn)(); const char* (*GetClipboardTextFn)();
void (*SetClipboardTextFn)(const char* text); void (*SetClipboardTextFn)(const char* text);
// Optional: override memory allocations (default to posix malloc/realloc/free) // Optional: override memory allocations (default to posix malloc/free)
void* (*MemAllocFn)(size_t sz); void* (*MemAllocFn)(size_t sz);
void* (*MemReallocFn)(void* ptr, size_t sz);
void (*MemFreeFn)(void* ptr); 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) // 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)