4 ms·
> Heap Memory - new, delete Keywords Should "modern" C++ even use new/delete? I'm a C++ n00b, but I thought these can be avoided entirely now.
by laweijfmvo 3y ago
> Heap Memory - new, delete Keywords
Should "modern" C++ even use new/delete? I'm a C++ n00b, but I thought these can be avoided entirely now.
- jacopoipoi 3y agoIt's explained later in the course
- underdeserver 3y agoNot entirely - you can't generally use std::make_unique with private constructors.
- nitnelave 3y agoYes, in new code you should be able to replace almost all new and delete with unique_ptr, vector or, more rarely, shared_ptr. Placement new can still be useful, but delete not really. There are some patterns where you use new without a delete for a global singleton that is intentionally never deleted, as well. It's still useful to learn about the concept when dealing with old code.
- kimixa 3y agoI noted that - IMHO one of the big advantages to "modern" c++ is the focus on the lifetime of objects with smart pointers rather than the mechanics of heap allocation and pointers. Pushing that down to chapter 19 as "Advanced Topics" seems like a mistake. Arguably the same with std::array vs object[] - the first should "probably" be the default now for teaching new programmers, so covered first (or at least highlighted when discussing array[]-style variables) I also note a number of the possibly-ambiguous c-style casts in examples, despite already having mentioned the explicit versions (static_cast and the like). Plus there seems to be a fair bit of system & machine dependent stuff mentioned like it's /always/ true - like stack being at a "higher" address space than the heap and code sections, or the stack growing down. It also says that the Data section is "slower" than the stack which... isn't true? If they're spilled out of registers, they're likely functionally identical? Or at least for small microbenchmarks depend on specific implementation details, like how the pointer to the object is calculated and dereferenced.... And object size and cache interactions... And a million other things... And that's just the first few chapters I looked at :P
- doctorpangloss 3y agoSmart pointers should really be like, chapters 2-10. In my experience, every useful C++ application requires wrangling some historic smart pointers implementation: Boost, Unreal, libwebrtc, Qt. Even NVIDIA uses its own smart pointers (thrust::device_ptr) though that's understandable. Also there's stuff like this: https://stackoverflow.com/questions/65938991/how-to-use-lambda-with-templated-stdunique-ptr https://stackoverflow.com/questions/65938991/how-to-use-lamb... for e.g. TensorRT.
- deleted 3y ago[deleted]