ComboBox.getText()

Hi, is there any special reason, why ComboBox.getText() returns String and not const String& ? The point is that I need to render the current selected text elsewhere in the window (g.drawText() ...) and don't really like the idea of this dynamic memory allocation and copying during the rendering phase.

 

Thanks a lot for any answer

Yes, there are good reasons for that return type, but more importantly, it's incredibly naive to think that something like this would have a measurable impact on performance! If performance matters, then you need to learn to use a profiler and actually measure where the real bottlenecks are before you waste your time worrying about irrelevant things like this.

(..not to mention that copying a string doesn't even allocate any memory!)

Well, thank's. Performance is not a problem at this point. It is just that I used to work on mobile games and there was a lot of problems with string (std version) copying during rendering, including the fact that it keeped incrementing the allocation ID, making it hard to reproduce any memory-related bugs.

 

Anyway I wasn't aware of this juce::String optimization, so either way the "problem" is solved.

Sure, but in the process of rendering, there'll be countless other allocations happening - every path, graphics context creation, etc etc will involve all kinds of behind-the-scenes allocations. Even if every string copy did allocate, it probably still wouldn't show up as a significant issue when you profile the app.