Repository navigation
Replies: 11 comments 1 reply
|
What are you suggesting? |
|
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. |
|
I see. |
|
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;
|
|
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... |
|
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 |
|
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 |
|
@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. |
|
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;
} |
|
one idea of performance optimization is substitute std::map to std::unordered_map whenever possible. |
|
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. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Discussion thread about performance tuning like shared_ptr, move semantics, r-value and etc, etc.
related:
#6839
#6867
ping: @dimitre @roymacdonald @ofTheo
All reactions