Hacker News new | ask | show | jobs
by remar 3114 days ago
I had a similar conundrum when I was trying to learn modern C++ by writing a network stack. On one hand just wrapping my packet objects with a {shared,unique}_ptr meant that I could freely pass these objects through a pipeline and not worry about lifetime or accidentally freeing somewhere I shouldn't have.

Although it seems to me that most people seem to be proponents of actually sitting down and working out object ownership of your classes rather than just being lazy and using smart pointers everywhere.

I'm still experimenting with this approach, definitely slows me down right now but I imagine that's because I haven't done it enough. Not going to lie, coming from Java/C#, it's really convenient just being able to 'new' an object and not worry much about its lifetime.

1 comments

I don't think it's lazy to pass around smart pointers. Obviously you need to understand the consequences but in many cases like pipelines it's a pragmatic solution that saves a lot of code.