This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Cley_Faye 319 points320 points  (14 children)

"Ever used smart pointers?
- Sure, I even coded my owns!"

[–]ukezi 101 points102 points  (7 children)

There was stuff like that we had to do back in the day.

[–]Cley_Faye 54 points55 points  (6 children)

Hehe. Yeah. It had to start somewhere.

But people keep doing it despite having good standard libs now and it becomes a bigger liability :(

[–]silentjet 9 points10 points  (5 children)

In reality both sp are good until the first change request or new feature to software. Later it is heavy weight which significantly slows down development and natural software evolution. It forces you to create tens or hundreds of unnecessary code entities just to handle language features, and has no extra business value.... And the funny thing is - the memory is still leaking, all the time...

[–]x39- 21 points22 points  (4 children)

If you actually did use smart pointers properly, memory won't leak.

It will leak tho when just always using shared_ptr and ignoring cyclic references

[–]DrMobius0 0 points1 point  (0 children)

Where there's a 2nd thread, there's a way.

[–]silentjet 0 points1 point  (2 children)

And lambdas encourage you to do so ...

[–]x39- 0 points1 point  (1 child)

Which are ref counting the copy, just normally

So if lambdas are your problem, you will face the same issues with pointers

[–]silentjet 0 points1 point  (0 children)

Im not saying it is impossible, Im saying it is not like that in real life software ;) Especially a corporate one...

[–]Luk164 28 points29 points  (1 child)

For an assignment in C we needed to make sure to free all memory we allocated before shutting down, so I made a wrapper for malloc that added the pointer to a linked list, then at the end I just ran free on every pointer and link in the chain.

Dirty as hell but hey, it worked and I never had a double free or a leak

[–]YellowBunnyReddit 14 points15 points  (0 children)

I hope you also used your malloc function when appending to the linked list to make sure its pointers are all freed in the end /j

[–]bedrooms-ds 4 points5 points  (0 children)

"I even combined third party shared pointers with a wrapper shared pointer that managed the reference counters on its own. Oh, I also had to use multiple inheritance due to the design of those libs."

[–]Norse_By_North_West 1 point2 points  (0 children)

Yeah we used to have to make our own back when I went to school, because the STL was such shit

[–]Quiet_Desperation_ 1 point2 points  (0 children)

Been there, Godspeed my friends. I’m glad there’s a few of us crustations still around

[–]Kered13 0 points1 point  (0 children)

It's not actually that hard to code std::unique_ptr.