#Is unique_ptr the gold standard?

18 messages · Page 1 of 1 (latest)

weak grotto
#

In my coding school we first learn C to grasp the fundamentals of programming, so yeah malloc in freeing was a pain in the ass but I guess I'm used to it now haha, so using new and delete is more intuitive to me.
I've been doing my first personal project using unique_ptr and I want to know is it really worth it for one because once you are used to it it's much more convenient and two in terms of job opportunities like is this really the standard now in professional environments?

analog auroraBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

lost light
#

unique_ptr and shared_ptr are outrgiht better then new / delete in almost all cases

weak grotto
#

ok well thanks, I guess you cleared my doubts instantly

analog auroraBOT
#

@weak grotto Has your question been resolved? If so, type !solved :)

quick terrace
#

unique_ptr is 100% what you should be using

#

pretty much never malloc/free in C++, and also pretty much never use raw new/delete

weak grotto
#

!solved

analog auroraBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

rotund oxide
#

I'm curious, what makes you think that it wouldn't be worth it? like, forget about job opportunities or whether it's some kind of standard. isn't it obvious that it's just a much better way to do things?

#

like, why would you want to not use RAII when you could use RAII?

shy rampart
#

in C exceptions do not exist, but in C++ they do, so in C++ unless you use destructors properly to do cleanup regardless of what code path your program runs, (unique_ptr's destructor can be user-customized) then you will often get leaks, or even worse, double frees

#

this is the C++ mechanism called RAII

slate needle
quick terrace
#

agreed

slate needle
#

And to some degree in some cases you can in theory never have to use dynamic memory initialization ever in C++