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?
#Is unique_ptr the gold standard?
18 messages · Page 1 of 1 (latest)
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.
it's pretty much industry standard, pretty much no one uses new / delete unless they need now
unique_ptr and shared_ptr are outrgiht better then new / delete in almost all cases
ok well thanks, I guess you cleared my doubts instantly
@weak grotto Has your question been resolved? If so, type !solved :)
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
!solved
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
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?
the convenience of the syntax is like, 30% of the reason why unique_ptr, exists, the real reason is the resource cleanup when exceptions happen
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
Only time you should really ever use it is if you HAVE to use it. Otherwise yeah always use smart pointers if you're able to. UwU
agreed
And to some degree in some cases you can in theory never have to use dynamic memory initialization ever in C++