- 47
- 135 369
Code for yourself
Switzerland
Приєднався 15 січ 2022
This channel is all about code. After more than a decade-long career in programming and designing software and a PhD in robotics and computer vision, I decided to have my own place on the Internet where I can chat about things I encountered throughout the years. The content will have more or less rigid courses on that or another programming language or technique, but might eventually morph into something less structured. Only time will tell. For now - welcome to this new journey and hope you will enjoy it with me!
The C++ Lambdas
Lambdas are just a thing without which it is impossible to imagine the modern C++ of today. Here we talk about what they are, what we can use them for and touch a bit upon how they function under the hood.
🙏 *Support what I do*
Please consider using the *super thanks* ❤️ !
Other options to show your support:
⏺ Join my channel and access the perks: ua-cam.com/channels/Rm39hwBxsX-8yj2xs3OJjQ.htmljoin
⏺ Support me on Patreon: patreon.com/code_for_yourself
⏺ Sponsor me on GitHub: github.com/sponsors/niosus
📚 Link to the script to this video on GitHub: github.com/cpp-for-yourself/supplementary-materials/blob/main/lectures/lambdas.md
🔗 *Links*
⏺ Lambdas: en.cppreference.com/w/cpp/language/lambda
⏺ std::sort: en.cppreference.com/w/cpp/algorithm/sort
⏺ Function to pointer conversion: en.cppreference.com/w/cpp/language/implicit_conversion#Function-to-pointer_conversion
⏺ Function objects: en.cppreference.com/w/cpp/utility/functional
⏺ std::find_if: en.cppreference.com/w/cpp/algorithm/find#Version_3
⏺ std::for_each: en.cppreference.com/w/cpp/algorithm/for_each
⏺ std::transform: en.cppreference.com/w/cpp/algorithm/transform
#cplusplus #programming #coding #tutorial
🙏 *Support what I do*
Please consider using the *super thanks* ❤️ !
Other options to show your support:
⏺ Join my channel and access the perks: ua-cam.com/channels/Rm39hwBxsX-8yj2xs3OJjQ.htmljoin
⏺ Support me on Patreon: patreon.com/code_for_yourself
⏺ Sponsor me on GitHub: github.com/sponsors/niosus
📚 Link to the script to this video on GitHub: github.com/cpp-for-yourself/supplementary-materials/blob/main/lectures/lambdas.md
🔗 *Links*
⏺ Lambdas: en.cppreference.com/w/cpp/language/lambda
⏺ std::sort: en.cppreference.com/w/cpp/algorithm/sort
⏺ Function to pointer conversion: en.cppreference.com/w/cpp/language/implicit_conversion#Function-to-pointer_conversion
⏺ Function objects: en.cppreference.com/w/cpp/utility/functional
⏺ std::find_if: en.cppreference.com/w/cpp/algorithm/find#Version_3
⏺ std::for_each: en.cppreference.com/w/cpp/algorithm/for_each
⏺ std::transform: en.cppreference.com/w/cpp/algorithm/transform
#cplusplus #programming #coding #tutorial
Переглядів: 4 544
Відео
Never free memory yourself! Do this instead (in modern C++)
Переглядів 3 тис.3 місяці тому
Arguably this is the most important video to understand how memory is allocated in C . Even more, we cover not just how it can be allocated manually but how it allows C to be so fast as well as how to do it safely in modern C . *We cover* ⏺ What memory management is ⏺ Why garbage collection is not the way to go ⏺ What is stack and how it enables quick allocations and de-allocations of small var...
INHERITANCE in C++ | most of the things you need to know for OOP and beyond 🚀
Переглядів 1,2 тис.4 місяці тому
In this video we cover most of the things that one might encounter when working with inheritance in modern C . We go over a broad list of topics, starting from why we care about inheritance (spoiler alert: to enable dynamic polymorphism) and digging down into the rabbit hole of how it mixes with implementation inheritance (not that well), what is object slicing and what we need to keep in mind ...
Separate declaration and definition for C++ templates? Yes please (sometimes)
Переглядів 2,3 тис.5 місяців тому
It seems that the topic of compiling templated code in C into libraries is one of the typical contention topics for lots of people when they use templates in their code. In this video we look into why this topic can be perceived as such a complex one as well as how we can actually achieve what we want. 📚 As always, you can find the full script to this video as well as all the code shown on the ...
Why use forwarding references and how they are different from rvalue references in C++
Переглядів 2,6 тис.6 місяців тому
Since C 11 was released there has always been quite some interest in forwarding references among people practicing C . On one hand, it is a very powerful mechanism, on the other, it requires quite some knowledge about how templates work so it is met with a lot of fear among people learning C . In this video, we cover everything there is to know about forwarding references, why we might want to ...
How to use CLASS TEMPLATES, type traits, partial and full class template specialization
Переглядів 1,3 тис.7 місяців тому
Class templates with the ability to partially and fully specialize them are arguably what makes C so powerful! We cover most of what one needs to know about what class templates are, how to specialize them fully or partially as well as how it all plays its role if we want to implement type traits. Before you watch this video I recommend you to watch these videos if you haven't already: - *why* ...
How to use FUNCTION TEMPLATES - a comprehensive guide for modern C++
Переглядів 2,8 тис.9 місяців тому
Writing function templates is part of the core skills we can use as a C programmer! Today, we cover close to everything there is to know about this topic skipping only very few cases that we leave for the future. Before you watch this video I recommend you to watch these videos if you haven't already: - *why* use templates: ua-cam.com/video/1Mrt1NM3KnI/v-deo.html - *what* templates do under the...
Templates under the hood
Переглядів 1,4 тис.10 місяців тому
The second video out of a number of videos about templates. Here we focus on *what* templates do under the hood. Or, more precisely what a compiler does when it sees templated code. If you want to know *why* use templates in the first place, see: ua-cam.com/video/1Mrt1NM3KnI/v-deo.html 📚 As always, the script to the video lives here: github.com/cpp-for-yourself/supplementary-materials/blob/main...
Why use templates in modern C++
Переглядів 2,3 тис.10 місяців тому
The first video out of a number of videos about templates. Here we focus on *why* anybody would want to use templates in the first place, leaving the details to what templates do and how to properly use them in C to the future videos. If you want to know *what* templates do under the hood, see this video: ua-cam.com/video/NKvEbPVllRE/v-deo.html 📚 As always, the script to the video lives here: g...
Use static in classes (when needed) in modern C++
Переглядів 1,7 тис.Рік тому
Everything that you wanted to know about static (when it is used *inside* of classes) but were afraid to ask. For when (not) to use static *outside* of classes, see ua-cam.com/video/7cpPQunjv4s/v-deo.html 📚 As always, the script to the video lives here: github.com/cpp-for-yourself/supplementary-materials/blob/main/lectures/static_in_classes.md 00:00 - Intro 01:26 - Static class methods 04:54 - ...
Don't use static (outside of classes) in modern C++
Переглядів 6 тис.Рік тому
Everything that you wanted to know about static (when it is used outside of classes) but were afraid to ask. The video on using static *in* classes can be found here: ua-cam.com/video/ggNCjDPShrA/v-deo.html UPD: Had to re-record and re-upload due to some issues with the previous attempt at this video. 📚 As always, the script to the video lives here: github.com/cpp-for-yourself/supplementary-mat...
Const correctness in C++
Переглядів 3,5 тис.Рік тому
Here we look at const correctness as one of the cornerstone parts of C . We already know how to write our functions and classes and have access to all use cases where we can and want to use const keyword. So we cover most of these use cases here. 📚 As always, the script to the video lives here: github.com/cpp-for-yourself/supplementary-materials/blob/main/lectures/const_correctness.md
Project: Pixelate Images in Terminal 😎
Переглядів 1,4 тис.Рік тому
We've learnt a lot until now. We know how to write classes, how to implement proper move semantics for them as well as how to create full projects with CMake. Now it is time to put it all to a test by implementing a project that allows us to load an image from disk, pixelate it and show it to the user in the terminal. 📚 As always, the script to the project description lives here: github.com/cpp...
Headers and libraries, but with classes
Переглядів 1,7 тис.Рік тому
We know how to write libraries when using just functions. Is it any different when we use classes? We'll figure out in this video! Turns out the situation is nearly the same as when not using classes with just a couple minor differences. 📚 As always, the script to the video lives here: github.com/cpp-for-yourself/supplementary-materials/blob/main/lectures/headers_with_classes.md The chatbot use...
Safely copying, moving, and destroying objects in Modern C++ with the rule of "all or nothing"
Переглядів 2,6 тис.Рік тому
Which constructors does a C class need? Which does it generates on its own? What about various assignment operators? And a destructor? How not to shoot ones leg off and navigate these waters effortlessly? This and more we cover in this video that tells us a simple rule to follow when implementing classes in Modern C , the rule of "all or nothing". We dive into the reasons for its existence and ...
Re-inventing move semantics in modern C++ in 13 minutes
Переглядів 7 тис.Рік тому
Re-inventing move semantics in modern C in 13 minutes
C++ object lifecycle 101: the essentials
Переглядів 1,2 тис.Рік тому
C object lifecycle 101: the essentials
Mastering C++ pointers: the pros and cons of (raw) pointers | pointer usage with const
Переглядів 1,9 тис.Рік тому
Mastering C pointers: the pros and cons of (raw) pointers | pointer usage with const
Can you write a proper CMake library? | homework 📚
Переглядів 1,8 тис.Рік тому
Can you write a proper CMake library? | homework 📚
Do you even test? (your code with CMake)
Переглядів 26 тис.Рік тому
Do you even test? (your code with CMake)
🏗️ Build your libraries easier using build systems
Переглядів 1,7 тис.2 роки тому
🏗️ Build your libraries easier using build systems
C++ libraries and what inline has to do with them
Переглядів 3,8 тис.2 роки тому
C libraries and what inline has to do with them
Functions in modern C++ and some related best practices 👌
Переглядів 1,5 тис.2 роки тому
Functions in modern C and some related best practices 👌
Common compilation flags and debugging a C++ program
Переглядів 1,8 тис.2 роки тому
Common compilation flags and debugging a C program
Good delivery. But isn't good at describing why the choices you make are good. You present examples without describing the value for doing so or what happens if you choose other paths.
This is a fair criticism. This was a deliberate decision though. With CMake there are many ways to do things in an outdated way. I did not want to bring those up focusing on the current best practices to the degree of my knowledge instead.
Hey, Which editor did you use here?
@@hurainjinnath I’m using VS Code exclusively in this course.
@@hurainjinnath oh and there is also the standard macOS terminal
@@CodeForYourself thanks ☺
Sure, my pleasure!
I find this whole thing to be way too complex. That every developer needs to jump through all of these hoops in the year 2024, is ludicrous. All good IDEs should take care of all build steps, as MS Visual Studio does.
@@toby9999 I don’t fully agree. The modern CMake infrastructure is actually not too complex anymore. The benefit is that this system is something that we can use across any system without attachment to a specific compiler or ecosystem. It is much easier to design something when you are in control on where it is used and that’s the benefit that MS has. That being said, I never grew to like any IDE and my experience with VS (many years ago) was not the best. I guess what I’m trying to say is that to each their own but we all can benefit from a cross platform solution that is flexible enough to satisfy needs of most.
Дякуємо, Ігоре, за зрозуміле відео 👍
Радий, що вийшло плюс/мінус зрозуміло! 🙏
Useful info but why these noisy keyboard clicks, ha? It is a common knowledge that signs in an editor come from a keyboard. It just distracts.
@@arkadiuszszulc3303 I think I largely agree with you nowadays and that’s why in the recent videos I’ve done away with clocks altogether. That being said, it is a thing of personal preference and I do know people who prefer it with clicks because they like it aesthetically. It is hard to tailor to everybody. 😅 At this point I just hope it is not too distracting.
I wanna ask you about #pragma. Do they not prevent multiple definitions of the same header? If it is, why it didn't prevent when linking? I know libfoo and libbar are different libraries so we have multiple copies. But when linking with the main code, why we couldnt rerun #pragma 😄? Why #pragma doesnt make inline's job also. I couldnt understand this.
@@muhammedkocaer8373 thanks for the question! These are all confusing things. Let’s try to break them down. The pragma once is a preprocessor directive that can be seen by a # in front of it. This means that the compiler never sees it. Instead the preprocessor replaces it with some unique guard for this file so that when this file is included twice, it actually only gets included once. The include is also a preprocessor directive, so the compiler does not see it either. Instead, the preprocessor just textually replaces an include with the content of the underlying file. But only once because of the pragma once. Does this somewhat answer your question?
@@CodeForYourself Now I get it. I asked this question as if it were performing a function task. But I forgot that it was a preprocessor. Thanks.
@@muhammedkocaer8373 awesome! Glad I could help!
I seriously thought you were the LangFocus channel guy, I was like: "wait, does this guy also code?" Write the LangFocus channel and you gonna see that you guys are mostly identical. OMG
@@mohammedkamil5320 ok, to me we seem to be quite different but I like these types of connections. What would you say is similar? 😅
@ interesting, I would say your face is mostly similar, but the other guy’s face is a bit more broad. I think you guys have mostly the same eyes, same nose and same mouth, except for the hair. I showed you both for some of my friends just to make sure that I’m not the only one and most of them agreed that you guys look similar to each other except for one or two, but they also agreed that you have similarities😁
@ I don’t mind at all. Maybe one day I’ll have as many subscribers too 😅
Excellent video! Subscribed. And a video on concepts, please.
finally someone who doesn't only teach C with classes but the actual C++ standards
1. Ask rhetorically 'what does it mean to call a function' 2. Says nothing about instruction cache, stack pointer, stack memory layout in general 3. Does not link to a video about inlining which is an extremely relevant topic
Please note that this video is intended for providing enough intuition for people who are not familiar with lambdas at all.
Great as always 🤯, Igor. yes to the concepts and please make a video on multi-threading and async-programming
@@marwanzaghloul6065 thanks! Noted! 🙃
me pretending to understand:
Just in case I can make anything clearer just tell 😉
IIRC lambdas and refs to other (local) variables (in their capture list) might be an issue, as lambdas are not closures over their environment. Such refs might be/get invalidated 🤔
@@bsdooby could be. Sounds logical. Would need to check
This is pretty high quality, hope this channel grows a lot
@@HomeofLawboy thanks so much! Every comment you guys make kinda brings this closer 😅🙏
Awesome 🎉 as always; and yes to Concepts 👍
Great content! Yes to Concepts!! and multi-threading..and coroutines too..ok, I am pushing it I know...
@@Maximus98245 coroutines probably won’t happen. Everything else might 😉
@@CodeForYourself Yeah, coroutines are for library developers. Not something that can be explained in a 10-20 minute youtube video.
Don't forget modules. Which we will get. Eventually...
Great video, would be nice to cover function pointers and std::functions also the differences and use cases.
@@segfault4568 yes, absolutely! I hope to be able to get to it at some point. But as I mentioned before to properly talk about std::function I would kinda need to chat about type erasure and I’m not sure if I should or if I can do it in a simple enough way. Thinking about it anyway.
I'd appreciate a lecture on concepts! Bare templates are a bit confusing and their error messages are confusing. I guess concepts help with understanding what the types are for in the template.
Yes, exactly. Let’s see if I get to record a video about this.
Lambdas are my favourite feature of C++. They enable so much expressiveness and because of them some consider C++ to be a functional programming language (or at least a programming language that can be written in a functional style). You should also do a video on std::function, which combined with lambdas makes for some really powerful coding patterns. Also, in C++23 they introduced std::move_only_function, which is a more optimized version of std::function for captured objects that are not copyable. And in C++26 they're introducing std::function_ref, which is a light-weight version of std::function. As for lambdas, it should be noted that they can be templated as well. And one more important thing about lambdas is that they return their result by value by default, meaning that if you want a lambda that returns a reference you need to specify its return type as "auto&" or "decltype(auto)" or something similar to this.
@@zamf thanks! All good points! I’m still mostly targeting C++17 here just to make sure I have something finished before moving on to new standards. So no goodies that you described. Also, I’m not trying to completely copy cppreference here. The aim is to give people enough knowledge to be able to dig further. Hope this explains a bit better some choices I make in these videos.
@@CodeForYourself I agree. I just think that std::function is a good candidate for a future video as a follow up to this one.
@@zamf definitely. That video I really want to record at some point but a proper deep dive into how it works requires type erasure and I’m not sure how long it will take me to distill it into a manageable explanation 😅
The biggest issue with std::function is that it doesn't respect the const-ness (other than a smaller issue of it might need to allocate and takes up 32 bytes as opposed to 8 for function pointer) struct Functor { int x = 0; void operator()() { ++x; } }; const Functor func; //func(); // good, this will not compile const std::function<void()> stdfunc = Functor{}; stdfunc(); // compiles, I can mutate const std::println("stdfunc.target<Functor>()->x == {}", stdfunc.target<Functor>()->x);
@@Maximus98245 That is weird, I agree. But it's a similar behaviour to const pointers and even to const std::reference_wrapper. So not that unexpected. At least it modifies a local copy of the data, so nothing else in the program is modified.
Amazing! comment to promote
@@viktordiadkov8768 thanks! Highly appreciate it! 🙌
Great video! I keep coming back to this when ever I need a refresher on maps. One thing I wish you had mentioned here is, the iterator invalidation/stable addressing. std::map and unordered_map guarantee that any references to the keys/values are valid after insertions and deletions but some 3rd party faster implementations (like Abseil) do not and I found this out the hard way. Overall awesome material!
@@Maximus98245 thanks! 🙏 You’re making a good point. I felt like this was more introductory video so skipped that. I probably should eventually talk about it but don’t know when I’ll manage. 😅
Why is the method where we download GTest sources, save them to our system, build them, and then include them in our project using something like this (look down) now deprecated? enable_testing() find_package(GTest REQUIRED) include(GoogleTest) add_executable(tests tests.cpp ) target_link_libraries(tests GTest::gmock GTest::gtest ) gtest_discover_tests(tests)
@@ozimandias1858 well, deprecated is a strong word for it, you’re right. But it is discouraged. The suggested way is to “live at head” as mentioned in their readme: github.com/google/googletest#live-at-head
@@ozimandias1858 they also only provide the fetch_content example in their docs: google.github.io/googletest/quickstart-cmake.html
Okay, thank you!
Is there a video on arrays? I search the word array and couldn't see anything on the playlist.
I guess the closest video to this would be this one on various STL containers: STL sequence containers (and friends) in modern C++ ua-cam.com/video/dwkSVkGsvFk/v-deo.html
I think it would be way better if there was less face cam and more visuals related to the topic being talked about or code screen.
I largely agree. Towards later videos I converged to a very different format.
Awesome, You are rock man!!!... 🌹💖
Hi there! C++ templates can produce the worst error messages. Could make some videos about that? How to understand template error messages and debug templated code?
Oh yes! That is a great idea! I wanted to make a video like that for a long time. It will take me a bit of time though as I have just started a new job and all my time is spent there for now. But I’ll get to it one of these days.
Really great, glad to discover your cmake videos. As I am looking into strange link errors with static libs made with C, used in c++ apps, but cmake somehow linking wrong things. That lib property thing could be something understand more. Thanks.
Glad I was of some help. One recommendation to debug this type of linking errors is to start small and try to get to the smallest reproducible example first. Good luck!
One of the best I have ever listened!
@@alperzobu9534 thanks for such a high praise!
Буду откровенен, пересматривал 4 раза, и все рано не во всем разобрался. Так и не понял, для чего нам сохранять переменные с каким-то текстом. Однако, отличное видео - нужно просто приложить немного усилий. Мне, кажется, ролика хватит, чтобы понимать 90% cmake файлов. Все четко, и без воды
Дякую за хороші відгуки! Стосовно змінних, загалом всі змінні в cmake це просто текст. І більшість цього тексту зберігається в кеші який потрібен для того щоб зберігати конфігурацію між запусками. А все інше про за я розказую то наслідки цього.
@@CodeForYourself Да, только момент с кешем не уловил. Все остальное кристально. Особенно понравилась презентация на гитхабе. Я вот раньше просто смотрел, ничего не повторяя. Сейчас Вы сказали "не тупить" и выполнить все самостоятельно. Начал это практиковать. Времени намного больше занимает, но после ощущение будто сам все сделал. А если вопросы есть, гпт использую. Еще раз спасибо :-). Подписка, лайк
@ozimandias1858 будьте обережні з гпт, адже він хронічно бреше. Будь які конкретні запитання можна також задавати тут або на гітхабі. Я відповідаю повільніше за гпт, але сподіваюсь що менше брешу 😅
Very nice video, thank you! What do you use for the code and diagram animations at the end?
Thanks for the compliments! Whenever you see code animations I use motioncanvas.io The rest of the animations, including the last diagram animation here about shared pointers, I make by creating images with the Apple's Freeform, import them into Davinci Resolve where I edit my videos, and do the rest of the animations there.
why did you use virtual on Write functions for jpegio and pngio at the final example code?
That is it make sure that when we call these functions we look up the actual functions to be called in the vtable. In the end of the example we pass a reference to an *IoInterface* object. So try to make sure you understand exactly what will happen when we call *Write* on such an object reference. Does this help?
@@CodeForYourself I understand what you mean but in the video you used "void Write(const std::filesystem::path& path, const std::vector<Color>& data) const override { std::cout << "Writing PNG to path: " << path << std::endl; }" function but on github you used "virtual void Write(const std::filesystem::path& path, const std::vector<Color>& data) const override { std::cout << "Writing PNG to path: " << path << std::endl; }" function for both png and jpeg. I expected and understood first function but did not understand second one.
@@erkamkocaer2097 oh! Now I understand! Thanks for pointing it out! It's a bug I have on GitHub. We *can* have *virtual* and *override* for the same functions but generally we should just use *override* as the *virtual* is implied here. So basically what I'm trying to say is that *override* implies *virtual*. I'll remove *virtual* from my GitHub code as it was probably a copy-paste error on my side. Thanks again!
@@erkamkocaer2097 I've updated the code on GitHub to not have *virtual* in the last example. Thanks again for bringing it up!
@@CodeForYourself thank you for your attention. I like your cpp videos. They are really impressive.
I’ve been watching your channel and following along from the start. This video just helped me tie a lot of concepts together. Many thanks, keep it coming!
Thanks a lot! Happy to hear it was useful!
why do a video? why not simple write a nicely written article that people can read at their own leisure, and one where you can correct the numerous issues raised on the cpp subedit
That is a valid question. The main reason is that some people prefer a video format and a video allows me to do both, have a markdown article and a video. You can find the markdown under the video. The downside is of course that errors are harder to fix.
@@CodeForYourself I'm one of those people who prefers a video format and I appreciate the work you do. I truly believe if you keep up the good work this channel will explode within the programming community. I'm recommending it to all my co-workers.
@JaredAlanXyz thank you sooo much for these kind words. I haven’t had the time to properly record new videos lately. But a couple are in the pipeline. 🙏
@@JaredAlanXyz do you not find that to be an issue? if the only way or most efficient way you can learn today is via videos, you're now wholly dependent on youtube/internet and also the cadence at which the presenter rolls the video
@@PerriPaprikash I want to note that _all_ of the things I say in every single video is available as text (markdown) in this GitHub repository: github.com/cpp-for-yourself/lectures-and-homeworks So I hope that people are getting the best of both worlds - a video explanation + all of the text and code for offline reading. Finally, I just want to note that recording and processing a video is not my main time sink. It takes me roughly 2-3 evenings at this point. Designing what I want to talk about, how I want to present it, what examples I need to provide to make it intuitive enough but not overly simple takes a much longer time, sometimes weeks-worth of evenings after work and some weekends. I would need to do the same work for text-only tutorials.
Then, he changed it back again at 6:05. 😂😮😅😅😅
@@richardbennett4365 Same explanation as for the first change. The blank T-shirt is the original recording and the “save the earth” one is the follow-up 😅
Nice, and why did the presenter change shirts at 5:10???
@@richardbennett4365 simple. I recorded everything and then, when editing found that the story wouldn’t add up. So had to re-record and add a part. But the old tshirt was already in the laundry basket 😅
About the manual delete, I always get questions from friends about whether they should use delete on a raw pointer they got as a return value from a function inside some old C library, It is all super confusing for beginners. Usually Documentation have it mentioned as "non-owning". It's amazing to see how all over the place each library's cleanup methods are.
@@segfault4568 yes, my experience exactly. That mess is exactly the reason for all the smart pointers 😬
I am just about to develop a “tree container”. The video content is so useful as an overview, clear, straight and didactic. Thanks
@@leonardodosanjoschaves6204 awesome! Glad to hear it was useful and good luck!
I am enjoying so much this course playlist. Thanks!!!
@@leonardodosanjoschaves6204 happy to hear that! 🙏
It's great that people got interested by memory management, but I fully disagree with the usage of smart pointers and garbage collectors as a reliable and performant way of managing memory. Those techniques assumes that every "object" has his own lifetime, witch is fundamentally false: When there's one, there's many. This affects performance because of memory fragmentation and loses capabilities. I highly recommend the talk of Ryan Fleury about Arena Allocators, it's mindblowing how simple and effective a linear allocator can be. I almost never think about memory management and have all the performance and reliability.
Arena allocators definitely have their use! However, if we allocate a lot of objects we will quickly need to manage memory in complex ways. This lecture targets largely the default behavior for beginners. I believe that using the heap for allocations should be completely fine in most domains. Also, heap implementations benefit from years of optimization and as far as I know they basically use arena like allocations for small objects. That being said, if one really writes a safety critical application and cannot use heap memory at runtime then yeah, we’ll probably need to allocate stuff from an arena. Also, I don’t agree with putting garbage collection and smart pointers in the same row. They are very different mechanisms. Smart pointers are definitely reliable and in case of a unique pointer have nearly no overhead. So if one wants to allocate on a heap, smart pointers are definitely a way to go.
This is quality content, your channel is underrated bro
@@advik-b thanks for your kind words! Spread the word then. Let’s fix it. 😅
love this explanation
Glad you liked it! 🙏
loving these videos.
Very Nice lecture, all my years I have always been a Composition over Inheritance supporter as well I knew that private inheritance can get the job done but never bothered to see how; example at 9:59 cleared the syntax and semantics up perfectly. ☺
Glad it was helpful! 🙏
Amazing content Igor, keep up the good work.
Thanks! I’ll try my best 👌
you always deliver a masterpiece related to C++. Thank you so much for sharing your knowledge :)
@@SanjeevKumar-nm7ps thanks so much for your kind words! You make me blush! ☺️ Glad that it is useful to you! 🙏
Great video, however I couldn't figure it out how you change your T-Shirt that fast 😄.
Oh, that’s very easy. You just mess up in the script, spend a week editing, then see that it’s wrong and that you have to re-record parts. 😅
Great. Do you have any udemy course in detail for c++. I would like to purchase it
Not yet, but maybe some day once I finish a full course here.
Nah man, RAII is there for a reason. There is no free lunch. It's an indirection that in many cases isn't necessary. Writing a quick free with a null check into a destructor is not hard. Smart pointers are great for some things, but a shared pointer is inefficient and a unique pointer is kind of obsolete in many cases. I think nuance would make this a bit better. They should not be your default move. You should always evaluate your options.
Could you elaborate a bit on how unique_prt is obsolete? This is the first time I hear about it.
How is Unique pointer obsolete? it executes the same instructions as Raw pointer, same size as well, Scott Myers even recommended them to be used in tight cycles. Shared pointer though not to be confused with Auto GC is still a deterministic destructor so plenty useful, the only inefficient thing I can recall about Shared pointer is that it is twice the size because of control block pointer.
@@segfault4568 I have a similar view (thus my original question to the OP). As for the shared pointer the reference count is atomic if I remember correctly, which requires synchronization and therefore might cost additional resources and instructions.
Nice explanation! By the way, what font-style, and colour-theme are you using? It looks pleasant to the eye!
Thanks! The font is Fira Code. The theme that you see in the animations is a custom one that more or less resembles the default vscode one.
@@CodeForYourself Thanks!
@@tirthasg sure, anytime!
Great explanation. Liked and subbed buddy
Thanks so much! 🙏