You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to discuss the parameter passing style of shared_ptr in examples and test cases. Through my learning journey, I noticed that some code snippets (e.g., those using std::shared_ptr<coro::io_scheduler>&) employ reference passing for better performance. While this approach works perfectly in scenarios with straightforward lifetime management, I'm concerned it could be potentially misleading for newcomers.
The C++ Core Guidelines passing shared_ptr by value when ownership sharing is needed, as it explicitly maintains the reference count. This becomes particularly important in coroutine contexts where suspended coroutines might outlive their frame objects - value semantics provide clearer ownership tracking.
Would you consider demonstrating the value-passing approach in examples as the default practice? I understand the reference approach might be intentional for specific optimizations, and I'd appreciate any insights you could share. If there are nuances I've misunderstood regarding the project's design philosophy, I'd be grateful for your guidance.
Regards.
The text was updated successfully, but these errors were encountered:
I think this is a good idea, you are right that when I originally created these examples a lot of them can work with references since the outer scope that the scheduler is created in outlives the coroutine. But I can definitely see how this is misleading for a real world example. I think using std::shared_ptr appropriately with copy semantics in the examples is the right direction.
Would you be willing to take a stab at updating them with a PR? If not I will try and get to it when I have some time since I do think this is the right move but might be a bit of time.
Uh oh!
There was an error while loading. Please reload this page.
I'd like to discuss the parameter passing style of shared_ptr in examples and test cases. Through my learning journey, I noticed that some code snippets (e.g., those using
std::shared_ptr<coro::io_scheduler>&
) employ reference passing for better performance. While this approach works perfectly in scenarios with straightforward lifetime management, I'm concerned it could be potentially misleading for newcomers.The C++ Core Guidelines passing shared_ptr by value when ownership sharing is needed, as it explicitly maintains the reference count. This becomes particularly important in coroutine contexts where suspended coroutines might outlive their frame objects - value semantics provide clearer ownership tracking.
Would you consider demonstrating the value-passing approach in examples as the default practice? I understand the reference approach might be intentional for specific optimizations, and I'd appreciate any insights you could share. If there are nuances I've misunderstood regarding the project's design philosophy, I'd be grateful for your guidance.
Regards.
The text was updated successfully, but these errors were encountered: