@@joedartonthefenderbass Even without RUclips membership ? I initially thought maybe he uploaded it by error (or whatever) and then revert it to private. Responding to my own question : Even if it's not explicitly possible you can still have a video only accessible via the link and not listed on RUclips so yeah
> as much as we love C++ there are times where an existing library that is already written in C is a better choice than writing it in C++ * eyes ffmpeg nervously *
This is easily one of the best C++ channels out there. These videos help so much in getting to know the language better. If you ask me, I'm all for going over the most basic STL functions and how to make custom versions of them in some form.
The [[no_unique_address]] attribute is cool, but you forgot to mention that, taking the address of such member is UB. Quoted from the standard "Taking the address of such member results in an address that may equal the address of some other member of the same object." That means the getters for the deleter may actually return the owned ptr.
Calling the function from that pointer would be UB, but taking the address isn't itself UB. If it were, the compiler would happily apply the fact that Undefined Behavior Does Not Occur to optimize away the existence of the entire function, if you just took the address of the member and did some arithmetic on it. (This is the real purpose of UB btw: not only can the compiler do whatever it wants for the UB itself, it can assume that any program state or code path that would lead to UB is unreachable or does whatever is most convenient/optimal.)
My company is mandating c++17. I'm envious of everyone getting to use 20 in production. Have you covered writing Python-esque generators in C++? I think that'd be an interesting topic to cover.
Do you have all c++ topics covered... I am learning c++... I know rust cant replace c++ in the near future... As its deeply rooted in every legacy systems
On the contrary, *all* it does is allow members to overlap. en.cppreference.com/w/cpp/language/attributes/no_unique_address Obviously, it cannot allow overlap in real data, but in particular it can allow overlap in padding.
@@mCoding I think some people might need more explanation for that one. Possibly they didn't understand what it means that the standard requires an object take up at least one byte even though it doesn't actually exist which allows the overlap to not cause problems. Which is actually kind of a cool space optimization for something which may be used millions of times over in a single program at a given point in its life.
Yes, but as horrible as it is, it's still also really cool and I wish C had some of these features. This is why I'm writing my own language, C++ sucks and C is incomplete.
It actually is exactly what it sounds like. He even mentioned things like opening a file and having a custom deleter for closing a file. Not every resource is a heap allocation
@@Finkelfunk Ah, the title has two possible meanings :) with heap allocations, and heap-allocations. I wanted to know other allocations, but it's about completely different resources.
Pleasure to be mentioned in your video π.
Video uploaded 29 minutes ago, Pi Launchpad · 11h ago
@@heroe1486 people can be givern early access to the video
Its the pi man again!
@@joedartonthefenderbass Even without RUclips membership ? I initially thought maybe he uploaded it by error (or whatever) and then revert it to private.
Responding to my own question : Even if it's not explicitly possible you can still have a video only accessible via the link and not listed on RUclips so yeah
I'm not quite stuck on C++ 17, but I'm still rather interested in learning about the empty base object optimization. Thank you for this video!
> as much as we love C++ there are times where an existing library that is already written in C is a better choice than writing it in C++
* eyes ffmpeg nervously *
This is easily one of the best C++ channels out there. These videos help so much in getting to know the language better. If you ask me, I'm all for going over the most basic STL functions and how to make custom versions of them in some form.
Thank you mCoding for your insight! The custom deleter (4:23) for closing open files gives me a whole new meaning about the Deleter.
The [[no_unique_address]] attribute is cool, but you forgot to mention that, taking the address of such member is UB. Quoted from the standard "Taking the address of such member results in an address that may equal the address of some other member of the same object."
That means the getters for the deleter may actually return the owned ptr.
Calling the function from that pointer would be UB, but taking the address isn't itself UB. If it were, the compiler would happily apply the fact that Undefined Behavior Does Not Occur to optimize away the existence of the entire function, if you just took the address of the member and did some arithmetic on it. (This is the real purpose of UB btw: not only can the compiler do whatever it wants for the UB itself, it can assume that any program state or code path that would lead to UB is unreachable or does whatever is most convenient/optimal.)
Definitely do a video on Empty Base Object Optimization, and maybe even delve into Curiously Recurring Template Patterns as well!
My company is mandating c++17. I'm envious of everyone getting to use 20 in production.
Have you covered writing Python-esque generators in C++? I think that'd be an interesting topic to cover.
Thanks for clarifying that mystic "custom deleter" topic! I'd love to hear about Empty Base Object Optimization!
Do you have all c++ topics covered... I am learning c++... I know rust cant replace c++ in the near future... As its deeply rooted in every legacy systems
"rust users are typing" - more like "rust users are already rewriting"
Hats off to the library implementors. And as usual, nice video.
Im on C++ 17 and I want to hear how to do it! :)
But sometimes I just like leaking bit of memory here or there.
How's there not something like std::free_deleter functor in standard library, implemented like your FreeDeleter?
Can't you use C style unions to get both the deallocator and the pointer to share memory?
I am pretty sure [[no_unique_address]] does not allow members to overlap.
On the contrary, *all* it does is allow members to overlap. en.cppreference.com/w/cpp/language/attributes/no_unique_address
Obviously, it cannot allow overlap in real data, but in particular it can allow overlap in padding.
@@mCoding I think some people might need more explanation for that one. Possibly they didn't understand what it means that the standard requires an object take up at least one byte even though it doesn't actually exist which allows the overlap to not cause problems. Which is actually kind of a cool space optimization for something which may be used millions of times over in a single program at a given point in its life.
I'm commenting because I'd like to find out how to use less memory.
good fucking stuff.
Great video. But. But guys, don't you honestly think this stuff is horrible?
Yes, but as horrible as it is, it's still also really cool and I wish C had some of these features. This is why I'm writing my own language, C++ sucks and C is incomplete.
As Gabriel said, the title was not well explained in this video.
What other allocation would that be? Stack? Why would you need unique_ptr for that?
It actually is exactly what it sounds like. He even mentioned things like opening a file and having a custom deleter for closing a file. Not every resource is a heap allocation
4:14
@@Finkelfunk Ah, the title has two possible meanings :)
with heap allocations,
and heap-allocations.
I wanted to know other allocations, but it's about completely different resources.
🥂Rust
Okay but how unique_ptr is not just for heap allocations
He literally just explained that
You can use it for any resourse which needs to be cleaned up. Not every resource is a heap allocated memory.