Can an excessive use of smart pointers (especially shared_ptr) cause an increase in kernel calls?
I am trying to optimize and simplify a real-time (QNX) codebase. One focus besides memory and realtime efficiency is reducing system kernel calls. I've read through this and this, so I have a basic understanding that overusing shared_ptr's as call by value, might cause of some runtime performance issues. What I'm also curious about is whether this type of implementaions would also increase the kernel calls.
Please keep in mind that the processSend function is one of many functions that are called in a cycle and itself calls many other functions (like Default) in a similar way.
// getting called in every cycle (some milliseconds) void signal::processSend( std::shared_ptr<const structA> readPtrA, std::shared_ptr<const structB> readPtrB, std::shared_ptr<const structC> readPtrC) { last_send_data = this->Default(readPtrA, readPtrB, readPtrC); } void signal::Default( std::shared_ptr<const structA> readPtrA, std::shared_ptr<const structB> readPtrB, std::shared_ptr<const structC> readPtrC) { // some value readings }
shared_ptr. Whether those do kernel calls is less important than that you're doing a bunch of redundant work instead of just moving stuff. At the very least,processSendshould move its arguments intoDefault.// some value readings: This doesn't require taking (shared) ownership of the objects, so the parameters of that function shouldn't beshared_ptrs to begin with and can be raw pointers (or even references) instead. And then going backwards the same holds forprocessSendas well.std::shared_ptrwhenstd::unique_ptrwill do.std::unique_ptris usually zero-overhead.