You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stanislav Vasilev edited this page Oct 21, 2024
·
1 revision
This is an introduction to the custom memory management strategies you should be using to be writing "correct" code.
Introducing the custom allocator
The framework ships with a custom allocator(UImGui::Allocator) that should be used by your application. It contains all functions a standard C++ custom allocator should have.
This is needed to enable us to have plugins on Windows. It's good practice to use the custom allocator, however, it should be compatible with the normal standard allocator in most cases if you don't want to support plugins on Windows.
Caution
Make sure that you're using the correct wrappers on top of the regular standard library types. Standard library containers should not be used as is. More info can be found here.
C API
In the C API, you also have access to the following function as replacements for malloc and free:
UImGui_Allocator_allocate
UImGui_Allocator_deallocate
C API memory management
The C API provides you with 2 ways of managing your memory:
Auto-deallocated - for objects that have relatively the same lifetime as the application
Manually managed
In many interfaces, you can decide which deallocation strategy you want to use for a handle, by toggling the bManualDeallocation boolean argument that should be the last argument of the function that returns the handle. You can then call the respective free function for it.