Replies: 11 comments 1 reply
-
What are you suggesting? |
Beta Was this translation helpful? Give feedback.
-
sorry. I didn't explain it enough. I thought to need some policy about performance tuning. for example, about avoiding temporary copy of if something will call too many time, then I think overloading one more, I said on #6867 about ref qualifiers, and @ofTheo points out "can't see a huge reason to add this sort of complexity". and I agree to it now. thanks. |
Beta Was this translation helpful? Give feedback.
-
I see. |
Beta Was this translation helpful? Give feedback.
-
I think it is strange to use plain shared_ptr as a function parameter, so we can choose to use const & as a function parameter, or move inside the function, so we don't have multiple increment and decrement. And it would be great to evaluate if shared_ptr is needed in all cases. I could identify at least one case where it doesn't need to be used at all. std::map<std::shared_ptr<ofAppBaseWindow>,std::shared_ptr<ofBaseApp> > windowsApps;
|
Beta Was this translation helpful? Give feedback.
-
I completely agree what you say. Sorry if my understanding about what you say and what you understanding are wrong.
of course, if we move argument that typed as but I think what overloading both type of e.g. to change from:
to:
makes sense in below situations.
when I writing this reply, I notice unclarified issue about thread safeness of move shared_ptr... I need to more study... sorry if the my English is difficult to read... please read my opinion from codes... |
Beta Was this translation helpful? Give feedback.
-
Hi, @dimitre @2bbb Why dont we give it a try and see how it works. or at least having a list of places where this could be applied can help telling if it is either a good idea or not.
I think that there is a function where you can get the current window, which returns a shared_ptr, thus storing these as shared_ptrs makes sense. (I am just pulling this from the top of my head, not 100% sure) @2bbb Your english is perfectly fine. I understand you well, and I english is not my native language either. :D |
Beta Was this translation helpful? Give feedback.
-
There is a function in OF (important one, key to any project) that mixes raw pointers, references and shared_ptr. openFrameworks/libs/openFrameworks/app/ofAppRunner.cpp Lines 57 to 60 in 0251a37 |
Beta Was this translation helpful? Give feedback.
-
@dimitre as far as I can tell this works this same.
I generally use make_shared instead of new for shared_ptrs, not sure it makes much difference, but it does look a little cleaner. |
Beta Was this translation helpful? Give feedback.
-
Which style do you prefer and why? void ofSoundPlayer::setPlayer(shared_ptr<ofBaseSoundPlayer> newPlayer){
player = std::move(newPlayer);
} void ofSoundPlayer::setPlayer(const shared_ptr<ofBaseSoundPlayer> & newPlayer){
player = newPlayer;
} |
Beta Was this translation helpful? Give feedback.
-
one idea of performance optimization is substitute std::map to std::unordered_map whenever possible. |
Beta Was this translation helpful? Give feedback.
-
I think style like void method(type newValue){
value = std::move(newValue);
} is better. because both style are same count of copy. but user can use like but, if size of void method(const std::vector<float> &newValue){
value = newValue;
}
void method(std::vector<float> &&newValue){
value = std::move(newValue);
} is better, I think. |
Beta Was this translation helpful? Give feedback.
-
Discussion thread about performance tuning like shared_ptr, move semantics, r-value and etc, etc.
related:
#6839
#6867
ping: @dimitre @roymacdonald @ofTheo
Beta Was this translation helpful? Give feedback.
All reactions