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?
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.
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.
Cheers! There should be many great assembly lessons on TH-cam -- at some point I'll update my own (th-cam.com/play/PLvv0ScY6vfd9BSBznpARlKGziF1xrlU54.html) -- I tend to look at university courses, or otherwise compiler explorer to check assembly otherwise :)
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++? ;-)
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.
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?
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 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.
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++ ?
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)
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?
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 :)
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.
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!
@@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 :)
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?
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.
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.
Cheers! There should be many great assembly lessons on TH-cam -- at some point I'll update my own (th-cam.com/play/PLvv0ScY6vfd9BSBznpARlKGziF1xrlU54.html) -- I tend to look at university courses, or otherwise compiler explorer to check assembly otherwise :)
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++? ;-)
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.
Thank you man. You are very good at this 👍
Cheers!
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?
Cheers! Try SFML
Good job Mike. I highly appreciate your crisp and point to point explanation. Keep it up 👍
Thank you for the kind words!
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.
Cheers! Thank you as always for the kind words!
Hey Mike,will there be any cmake series?
I have on my TODO list a series of ideas for a build systems series with 'shell scripts' 'make' 'cmake', and some other tools.
@@MikeShah Thanks a lot for the heads up!
@@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.
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++ ?
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)
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?
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 :)
Are exceptions in C++ expensive like in C#
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.
Noob question, why is Collection[0] = 7 a memory leak? Is it because we are not doing the delete Collection in the end?
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.
are you using mac with m1 chip? how can i detect memory leakage on mac with m1 chip ? i can't download valgrin.
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!
url will be: th-cam.com/video/bhhDRm926qA/w-d-xo.html (will be release by May 31, 2022)
Wonderfully explained as always. Thank You.
Cheers!
Thank you, I was waiting for this one. :)
Hehe you're most welcome Amit!
Thanks Mike!
You are most welcome! 😁
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!
Cheers, can you give a timestamp?
@@MikeShaharound 10:25
@@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 :)