Another smart_ptr question - pass by value or ref?

Started by
11 comments, last by Jan Wassenberg 16 years, 3 months ago
Quote:Original post by Sc4Freak
boost::shared_ptr is uaually also 4 bytes larger than a regular pointer, so that may be something to take into consideration.


Small enough for me - Thanks
Advertisement
From nitpick land:

void funcPassByRef( const boost::shared_ptr<bigObject>& b);


Would make even more sense.
Quote:This would imply that you have control over the function's signature. And if you do, then it's preferable to use a 'passing style' which correctly represents ownership:

That sounds reasonable if you're the sole developer in a smallish project, but looks to break down under real-world maintenance.
It's unlikely that every corner of the codebase uses these semantics, so the rule may not be clear to junior coders. What's to prevent them from taking the address and storing it? Writing a "if you use & on this parameter, you will be shot/fired" comment in all of these spots would be tiresome. Sure, they could still store ptr.get(), but at least those spots can be found, unlike operator&.
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3

This topic is closed to new replies.

Advertisement