Classes part 9 - Resource Acquisition is Initialization (RAII) Ep. 45

  Рет қаралды 7,862

Mike Shah

Mike Shah

Күн бұрын

Пікірлер: 39
@adityaanand4749
@adityaanand4749 Жыл бұрын
Good job Mike. I highly appreciate your crisp and point to point explanation. Keep it up 👍
@MikeShah
@MikeShah Жыл бұрын
Thank you for the kind words!
@bluehornet6752
@bluehornet6752 2 ай бұрын
Nice video, I especially like the reminder that the destructor is guaranteed to be called if an exception is thrown But I do have a question for you... Why are you returning an 8-byte integer reference from your operator[] overload(s), when you can simply return the (probably) 4-byte integer? Basically, I guess I'm wondering what the benefit is to returning reference to a primitive type in this case? Are you planning to allow method chaining or something? What would be the benefit(s) of doing it the way you did?
@MikeShah
@MikeShah 2 ай бұрын
In this particular instance you're right returning the value (4-byte integer) would be more optimal. For the strategy shown, returning the reference allows you to do: collection[idx] = some_value; // i.e. You can do the assignment by returning the reference.
@thestarinthesky_
@thestarinthesky_ Жыл бұрын
Great video! You're so awesome! references you're using and introducing in your channel for C++ says a lot how knowledgeable you're. Thanks for sharing with us.
@MikeShah
@MikeShah Жыл бұрын
Cheers! Thank you as always for the kind words!
@TheRawi
@TheRawi 4 ай бұрын
Thank you man. You are very good at this 👍
@MikeShah
@MikeShah 4 ай бұрын
Cheers!
@Sergei_developer
@Sergei_developer 3 ай бұрын
Great lesson as always. I'm just curious if there are such excellent resources for mastering the Assembly language. Thank you, sir for this amazing content and your precious time. Indeed, you deserve tremendous respect and many more views.
@MikeShah
@MikeShah 3 ай бұрын
Cheers! There should be many great assembly lessons on KZbin -- at some point I'll update my own (kzbin.info/aero/PLvv0ScY6vfd9BSBznpARlKGziF1xrlU54) -- I tend to look at university courses, or otherwise compiler explorer to check assembly otherwise :)
@bernhardkneer5393
@bernhardkneer5393 Жыл бұрын
Hi Mike, again a great video!! This new C++ makes it more and more hard to understand what is going on in the background. e.g. from 6:00 onwards with the overloading of the [ ] operator... how the hell does this statement myCollection[0] = 7; change the private data value? Is it because the [ ] operator returns a reverence to the memory of this index and then writing to it works? Is this some "dirty" implementation or is this normal in modern C++? ;-)
@MikeShah
@MikeShah Жыл бұрын
Public interface can change the private underlying data -- the goal is to not change any private variables directly, but rather do it through the operator[]. This is true in programming languages. The reason for having both versions, is that one is for read access (i.e. const), and one is for writing a new value.
@_w62_
@_w62_ Жыл бұрын
Thanks for another great video. Could you recommend any C++ based graphic libraries that make uses of RAII so that I can have a feel of actual use case of it?
@MikeShah
@MikeShah Жыл бұрын
Cheers! Try SFML
@dwolrdcojp
@dwolrdcojp 2 жыл бұрын
Thanks Mike!
@MikeShah
@MikeShah 2 жыл бұрын
You are most welcome! 😁
@amitmulay729
@amitmulay729 2 жыл бұрын
Thank you, I was waiting for this one. :)
@MikeShah
@MikeShah 2 жыл бұрын
Hehe you're most welcome Amit!
@dibyojyotibhattacherjee897
@dibyojyotibhattacherjee897 2 жыл бұрын
Hey Mike,will there be any cmake series?
@MikeShah
@MikeShah 2 жыл бұрын
I have on my TODO list a series of ideas for a build systems series with 'shell scripts' 'make' 'cmake', and some other tools.
@dibyojyotibhattacherjee897
@dibyojyotibhattacherjee897 2 жыл бұрын
@@MikeShah Thanks a lot for the heads up!
@Southpaw101
@Southpaw101 2 жыл бұрын
@@MikeShah This will be really useful Mike. I have been waiting on something with cmake and Vcpkg. Would really appreciate it and Thanks again for all these classes.
@dhanushs1802
@dhanushs1802 2 жыл бұрын
Wonderfully explained as always. Thank You.
@MikeShah
@MikeShah 2 жыл бұрын
Cheers!
@muhammedhasankayapnar9495
@muhammedhasankayapnar9495 Жыл бұрын
Hi Mike, thank you for this series. I learnt a lot as a person who just has python programming background. For large scale data processing, is there any chance also to introduce us CUDA programming as well with C++ ?
@MikeShah
@MikeShah Жыл бұрын
Cheers -- thank you for the kind words! I'll consider something like this in the future. I tend to lean towards OpenCL for compute as it is cross platform (though I've used both)
@windowsbuilderthegreat3121
@windowsbuilderthegreat3121 2 жыл бұрын
Are exceptions in C++ expensive like in C#
@MikeShah
@MikeShah 2 жыл бұрын
Yes, relative to regular executing code. This blog has some performance numbers to show the relative scale (10x slower for code, or 100x slower for optimized code). pspdfkit.com/blog/2020/performance-overhead-of-exceptions-in-cpp/ I have not reproduced the experiment to confirm the numbers. For high performance systems (games, low latency trading, etc.) consider carefully if exceptions are the right tool for handling errors at run-time.
@thestarinthesky_
@thestarinthesky_ 2 жыл бұрын
Hi Mike. Thanks for this great tutorial. By any chance do you think this tutorial can help me to nail a c++ interview questions? or do I need to know more?
@MikeShah
@MikeShah 2 жыл бұрын
Cheers! I hope these videos certainly do help! Going through the series (including some of the 'interview portions') should help! As always, make sure to practice, and try building a few simple projects :)
@Lopito_PP
@Lopito_PP 2 жыл бұрын
Noob question, why is Collection[0] = 7 a memory leak? Is it because we are not doing the delete Collection in the end?
@MikeShah
@MikeShah 2 жыл бұрын
I'm assuming you mean around the 3 minute mark? Because we never deallocate 'Collection' which is part of the 10 integers allocated on the heap.
@odaialkhodary7872
@odaialkhodary7872 2 жыл бұрын
are you using mac with m1 chip? how can i detect memory leakage on mac with m1 chip ? i can't download valgrin.
@MikeShah
@MikeShah 2 жыл бұрын
I do have a Mac M1, and the tool to use is called 'leaks'. Look out for a video later this week on how to use leaks!
@MikeShah
@MikeShah 2 жыл бұрын
url will be: kzbin.info/www/bejne/mJnLdYWjbpdpp6M (will be release by May 31, 2022)
@rinket7779
@rinket7779 Жыл бұрын
Bro I like your vids but this video is extremely misleading. You spend a large portion saying that destructors are still called if an exception is thrown in the constructor. This is just not true. Try it. The example you then show to illustrate your point catches the exception in the constructor before it has a chance to escape. This is of course the case, as no exception then escapes the constructor at all. So from the pov of the cstor no exception occurred at all. Making the entire point a bit silly 😅 Other than that, good set of vids though!
@MikeShah
@MikeShah Жыл бұрын
Cheers, can you give a timestamp?
@rinket7779
@rinket7779 Жыл бұрын
​@@MikeShaharound 10:25
@MikeShah
@MikeShah Жыл бұрын
@@rinket7779 Ah yes, fair point -- yeah if the object has not yet been constructed, we will not call the destructor from the constructor in the case of an exception. Agreed showing the try/catch/finally within the constructor does not demonstrate that behavior! Perhaps a deep dive video into exceptions in the future I will amend this :)
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН
번쩍번쩍 거리는 입
0:32
승비니 Seungbini
Рет қаралды 182 МЛН
-5+3은 뭔가요? 📚 #shorts
0:19
5 분 Tricks
Рет қаралды 13 МЛН
🚨 ممكن تكون حياتك في خطر! 🚨
0:33
MAG Iraq
Рет қаралды 7 М.
C++ Best Practices: RAII
7:35
Nick
Рет қаралды 17 М.
Why I don't "using namespace std"
14:35
The Cherno
Рет қаралды 400 М.
What is RAII (Resource Acquisition Is Initialization)?
17:11
pencilflip
Рет қаралды 14 М.
Back to Basics:  RAII in C++ - Andre Kostur - CppCon 2022
44:17
The Return of Procedural Programming - Richard Feldman
52:53
ChariotSolutions
Рет қаралды 62 М.
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН