If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Funciton: wxMenuItem::wxMenuItem
Parameter: name (the 3rd parameter)
Question: Is it not efficient enough to construct a wxString here? Take Qt for example, it provides QStringLiteral to solve the performance problem by eliminate memory allocating when constructing a string object.
wxT() is not needed anymore since (unless mistake) wxWidgets 3.0. So, you can just create your menu item like this below (and in one line). Here, _() allowing you to translate the label in an associated .mo catalog.
wxMenuItem* m_menuItem_new = new wxMenuItem(m_menu_file, wxID_ANY, _("&New"), wxEmptyString, wxITEM_NORMAL);
This said, the forum is dedicated to the use of wxWidgets, not its design. If you want to discuss the wxWidgets design, it's better to address your suggestions through mailing list: https://www.wxwidgets.org/support/mailing-lists/.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
eranon wrote:wxT() is not needed anymore since (unless mistake) wxWidgets 3.0. So, you can just create your menu item like this below (and in one line). Here, _() allowing you to translate the label in an associated .mo catalog.
wxMenuItem* m_menuItem_new = new wxMenuItem(m_menu_file, wxID_ANY, _("&New"), wxEmptyString, wxITEM_NORMAL);
This said, the forum is dedicated to the use of wxWidgets, not its design. If you want to discuss the wxWidgets design, it's better to address your suggestions through mailing list: https://www.wxwidgets.org/support/mailing-lists/.
New to wxWidgets, reading the book "Cross-Platform GUI Programming with wxWidgets" in 2005, which is about 13 years old.
Do you mean _("&New") is more efficient than wxT("&New")?
What does .mo mean?
I think you should look for performance issues where they matter. Creating GUI elements is not where performance matters. When you create a new gui element there is so much code executed in the background, the string creation is almost negligible.
doublemax wrote:I think you should look for performance issues where they matter. Creating GUI elements is not where performance matters. When you create a new gui element there is so much code executed in the background, the string creation is almost negligible.
wxWidgets is fast enough, however the faster the better with a little modification without any loss of clarity. Take Microsoft MFC for comparison, it uses a pointer for string parameter instead of CString, personally I prefer performance here:
If your GUI has poor performance, then you GUI is likely not a good design.
If your code has poor performance, better rethink your strategy.
MFC were designed to run only on MSW OS, no Unicode conversions, no OS independant, no so much other features. Perhaps a tiny portion of faster, but lot of lack-of-features code.
Ronald wrote:Do you mean _("&New") is more efficient than wxT("&New")?
No, I didn't say anything like that (when I want to optimize an app on speed I'm using the compiler's options, then I profile it to decide what are the blocks of code requiring an added effort from me -- and, first, I choose the right language for the right project (wxString handling will be always faster than, say, its Ruby equivalent), I simply suggested to use _() to allow you to translate the word "New" in case your app is a multilingual one. But if your app is monolingual, you don't need to use _() and "&New" will be enough.
Ronald wrote:What does .mo mean?
A ".mo" file contains the translation in one language of all the translatable strings coming from your app (typically, you extract all these strings toward a .po file that you'll edit in a dedicated editor -- e.g. Poedit -- which will be able to compile it in a final compiled .mo format; some hints here: http://docs.wxwidgets.org/3.0/overview_i18n.html)
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Ronald wrote:Do you mean _("&New") is more efficient than wxT("&New")?
No, I didn't say anything like that (when I want to optimize an app on speed I'm using the compiler's options, then I profile it to decide what are the blocks of code requiring an added effort from me -- and, first, I choose the right language for the right project (wxString handling will be always faster than, say, its Ruby equivalent), I simply suggested to use _() to allow you to translate the word "New" in case your app is a multilingual one. But if your app is monolingual, you don't need to use _() and "&New" will be enough.
Ronald wrote:What does .mo mean?
A ".mo" file contains the translation in one language of all the translatable strings coming from your app (typically, you extract all these strings toward a .po file that you'll edit in a dedicated editor -- e.g. Poedit -- which will be able to compile it in a final compiled .mo format; some hints here: http://docs.wxwidgets.org/3.0/overview_i18n.html)
Take Microsoft MFC for comparison, it uses a pointer for string parameter instead of CString
Nevertheless, the string data will be copied internally.
With a pointer, the function gets data from the memory the pointer points to without copy the string, the programmer should guarantee what the pointer points to should be valid.
With a pointer, the function gets data from the memory the pointer points to without copy the string, the programmer should guarantee what the pointer points to should be valid.
The called function does not take ownership, which means that the string data has to be copied. Otherwise every string you pass there except literals would have to be allocated on the heap and the caller would be responsible for destroying it (but when?). Which would be very inconvenient.
With a pointer, the function gets data from the memory the pointer points to without copy the string, the programmer should guarantee what the pointer points to should be valid.
It's a const pointer. Which means that a) the called function does not modify it and b) that the called function does not take ownership.
Otherwise every string you pass there except literals would have to be allocated on the heap and the caller would be responsible for destroying it. Which would be very unconvenient.
Yes. Considering multi language, wxString makes more sense. I have spent several days in trying MFC, because 1) it is more efficient for machine 2) the controls can be customized seriously, but found that it was not well supported by M$ now any more. I'll check wxWidgets again. Thanks.
You should never optimize a program without first profiling it. Without knowing where it is slow, you can spend too much time optimizing the wrong parts.
And you should never optimize a program until users complain it's too slow. Instead, write the program to be easily understood. A professional programmer does not even think about optimization unless they get a change order to speed up a program.
WARNING: Highly caffeinated . Approach with caution .
shawnhcorey wrote:You should never optimize a program without first profiling it. Without knowing where it is slow, you can spend too much time optimizing the wrong parts.
And you should never optimize a program until users complain it's too slow. Instead, write the program to be easily understood. A professional programmer does not even think about optimization unless they get a change order to speed up a program.
If it can be faster without any loss of clarity of code, why not?