I'm using ImGui.text() a lot.
Library is expecting a String. If I have a text value that is changing I have to generate a new String since it is immutable.
If I update imgui per frame, java allocates 4mb per second for strings.
I checked how Lwjgl does it. For setting Glfw window title for example.
public static void glfwSetWindowTitle(@NativeType("GLFWwindow *") long window, @NativeType("char const *") CharSequence title) {
MemoryStack stack = stackGet(); int stackPointer = stack.getPointer();
try {
stack.nUTF8(title, true);
long titleEncoded = stack.getPointerAddress();
nglfwSetWindowTitle(window, titleEncoded);
} finally {
stack.setPointer(stackPointer);
}
}
public int nUTF8(CharSequence text, boolean nullTerminated) {
long target = nmalloc(POINTER_SIZE, memLengthUTF8(text, nullTerminated));
return encodeUTF8Unsafe(text, nullTerminated, target);
}
// encodeUTF8Unsafe loops characters at CharSequence and writes them 1 byte at a time to allocated target.
So if we could somehow make the library accept CharSequences instead of Strings and copy those characters to native side without allocating anything that would be superb.
First off, thanks so much for your hard work.
I'm using ImGui.text() a lot. Library is expecting a String. If I have a text value that is changing I have to generate a new String since it is immutable. If I update imgui per frame, java allocates 4mb per second for strings.
https://user-images.githubusercontent.com/8594559/221267457-52ed2e52-ca97-4924-b039-98189f5d8764.mp4
I checked how Lwjgl does it. For setting Glfw window title for example.
So if we could somehow make the library accept CharSequences instead of Strings and copy those characters to native side without allocating anything that would be superb.