Hello,
Consider changes below:
imgui.h
IMGUI_API const ImVec2& GetWindowSize() const;
imgui.cpp
const ImVec2& ImGui::GetWindowSize() const
{
}
Hello Andrey,
That doesn't make sense because ImGui is a namespace, not a class which you instantiate. All the functions are loose functions within that namespace.
What about return by reference instead by value?
Not all those functions return values that are persistently stored somewhere (they are computed).
What are you trying to achieve with those changes?
As can I see, ImGui::GetWindowSize() returns ImVec2 Size field of ImGuiWindow struct, nothing more.
But that would be leaking an implementation detail that may change in the future, and many similar functions don't do that.
What are you trying to achieve with those changes?
What are you trying to achieve with those changes?
Performance.
Rely on RVO is not good idea, I think. I mean "that it is possible to return by reference, it is better to return by reference".
ImGui has to work good in debug too where there won't be any RVO. Also ImVec2 is 8 bytes AFAIK, a reference is usually a pointer under the hood which on 64bit machines is also 8 bytes. So nothing gained.
As I undestand, in this case we have temp value and copy 8 bytes at least.
In reference case we have only one pointer (8 bytes on 64bit arch, as you mentioned above) without temp value and copying.
If you test you will see performance is not changed. In release both code is the same. Only debug matters.
Small example
struct s
{
float x, y;
};
s Array[10];
s getByValue(unsigned idx)
{
return Array[idx];
}
const s& getByReference(unsigned idx)
{
return Array[idx];
}
llvm 3.8.1 -O2 https://godbolt.org/g/d69MtS
and gcc 6.3 -O2 https://godbolt.org/g/qviqBH
GetWindowSize() which isn't on anywhere near the critical path of any reasonable app, when thousands of other functions are traversed.GetWindowSize() useful to calculate window size aligned to bottom or right side.GetWindowSize() ;)GetWindowSize() get access to non constant value.If you care about perf look at all the comments Omar added for perf todo's and fix those.