Тёмный

Back to Basics: C++ Smart Pointers - David Olsen - CppCon 2022 

CppCon
Подписаться 149 тыс.
Просмотров 46 тыс.
50% 1

cppcon.org/
---
Back to Basics: C++ Smart Pointers - David Olsen - CppCon 2022
github.com/CppCon/CppCon2022
Smart pointers were one of the many powerful additions to C++11, providing programmers with easy-to-use tools to help manage memory resources and avoid certain kinds of memory errors. This back-to-basics session will give you a solid foundation in smart pointers, explaining what smart pointers are in general and how to use the standard smart pointer types std::unique_ptr and std::shared_ptr. It will present a set of clear guidelines for when and how to use smart pointers. Attendees will leave this session having learned, among other things, how to write code that never leaks memory.
---
David Olsen
David Olsen has more than two decades of software development experience in a variety of programming languages and development environments. For the last six years he has been the lead engineer for the NVIDIA HPC C++ compiler, focusing on running parallel algorithms on GPUs. He is a member of the ISO C++ committee, where he was the champion for the extended floating-point feature in C++23.
---
Videos Filmed & Edited by Bash Films: www.BashFilms.com
RU-vid Channel Managed by Digital Medium Ltd events.digital-medium.co.uk
#cppcon #programming #coding

Наука

Опубликовано:

 

28 ноя 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 48   
@violetashopova3586
@violetashopova3586 Месяц назад
THIS GUY! ... every talk he did i watched so far is worth its time in gold
@coolwinder
@coolwinder 11 месяцев назад
This talk is too good, incredible information presented. I have used this talk to sprawl my research and understanding of mentioned topics. Thanks David, this is much appreciated!
@qksuna
@qksuna Год назад
Excellent talk, thank you! Appreciate always revisiting some fundamentals.
@Bolpat
@Bolpat Год назад
I’m currently in the process of updating a pre-C++11 codebase and some rules I imposed to myself is: * Never assert(ptr_parameter); If you find yourself doing this to a parameter, it should be a reference. If necessary, the caller must assert. * never new and delete (“// transfers ownership” doesn’t cut it) * For arrays, use container types (e.g. std::vector, std::array) and (custom type) ranges and iterators Then, any T* is a nullable non-owner pointer to a single object. Exceptions apply when calling library functions I have no control over, but if _my_ function takes/returns a int* it expects/returns a nullable non-owner pointer to a single object.
@aprasath1
@aprasath1 20 дней назад
Wonderful video!!! Very well explained covering lots of issues with usage as well.
@dkutagulla
@dkutagulla Год назад
Excellent talk ! Learnt a lot.
@acur665
@acur665 5 месяцев назад
Great talk - thank you for the fundamentals here!
@on2k23nm
@on2k23nm 6 месяцев назад
Thank you ! Talk was good, learnt a lot !
@Roibarkan
@Roibarkan Год назад
48:20 the type-erased nature of shared_ptr deleters can sometimes relieve issues related to multiple heap situations, ensuring an object gets deleted from the heap it was allocated from
@coolwinder
@coolwinder 11 месяцев назад
What is type-erased, also mentioned in 42:30, where it was mentioned as a resone for unique_ptr having deleter as template parameter and share_ptr a constructor argument for an instance of deleter? Thanks in advance :)
@xiao_sings
@xiao_sings Год назад
this was great!
@mohamedhussien4013
@mohamedhussien4013 Год назад
Awesome, thank u so much.
@eeshvardasikcm
@eeshvardasikcm 2 месяца назад
Thanks!
@Bolpat
@Bolpat Год назад
6:32 I’d add that a raw pointer should be nullable. If it’s non-owning and points to a single object, if it’s also not supposed to be null, what’s the difference to a reference?
@nhanNguyen-wo8fy
@nhanNguyen-wo8fy Месяц назад
9:29 unique pointer as member of class
@shivakumark.o846
@shivakumark.o846 5 месяцев назад
Thankyou
@Roibarkan
@Roibarkan Год назад
14:02, 29:17 (slightly advanced) note that self-move (e.g. “a=std::move(a);”) is not considered something that move-assignment should guard against. Copy-assignment should typically guard against self-assignment, and this is guaranteed for shared_ptr.
@coolwinder
@coolwinder 11 месяцев назад
Is this some guideline? Thanks
@anon1963
@anon1963 9 месяцев назад
@@coolwinder yeah since when you move an object, you set the pointer of the other object to nullptr. when you self move you set your object's pointer to nullptr. memory leak.
@oraz.
@oraz. 11 месяцев назад
The variable length arrays in the examples are ok?
@jjk15
@jjk15 Год назад
nice
@flocela
@flocela 9 месяцев назад
at 33:38 on line 2. "a" gets passed into the thread function's parameter "b". Wouldn't that increment count. There's no red arrow showing increment count on line 2. A bit hazy on this, if anyone would answer, that would be great!
@zhongxina9569
@zhongxina9569 8 месяцев назад
I got the same question haha
@bva0
@bva0 6 месяцев назад
I think the compiler optimizes that away (assuming you don't compile with -O0) in this case.
@David_Olsen
@David_Olsen 4 месяца назад
You are right. I missed the increment when the child thread's 'b' is initialized from the main thread's 'a'. I should have noticed that the number of increments and decrements didn't match. The main point of that slide, that the increments and decrements don't introduce data races, is still valid.
@Roibarkan
@Roibarkan Год назад
45:42 another good talk about some nice variations of smart pointers: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-sjLRX4WMvlU.html
@cunningham.s_law
@cunningham.s_law Месяц назад
if a unique pointer is the same in memory as a raw pointer, does that mean that I can reinterpretcast a raw pointer as a unique pointer and have it call the destructor?
@David_Olsen
@David_Olsen 12 дней назад
No. Don't try to do that. It won't work. A unique_ptr probably has the same memory layout as a raw pointer, but that is not guaranteed. Doing a reinterpret_cast does not create an object, so the destructor of the unique_ptr will not be run. If you have a raw pointer and you want its memory to be freed automatically, define a unique_ptr variable with the right lifetime and pass the raw pointer to the constructor.
@leili6490
@leili6490 Год назад
35:38 some member of the committee should be ashamed of their inefficiency. they always use “pursuing perfection” as an excuse, but in fact they spent one three-year after another, and got one half-finished product after another
@rutabega306
@rutabega306 Год назад
I'd argue that the first two examples don't need smart pointers.. what's wrong with std::vector??
@frenchmarty7446
@frenchmarty7446 Год назад
Sometimes better performance (for creation and destruction*, not access which is the same) and less memory. Plus they signal to everyone that they shouldn't change in size. *there are exceptions where std::vector outperforms such as when the size is very large or you want to use std::move.
@David_Olsen
@David_Olsen 12 дней назад
std::vector could have been used in those examples, but I don't see it as the best solution. std::vector can fix some of the memory management problems as smart pointers. But std::vector also has all the semantics of a resizable array. Sometime you don't want that or need all that extra stuff. In the first two examples, all that was needed was to automatically free the memory. std::unique_ptr does exactly that, and nothing more, so it is the best fit for those situations.
@pawello87
@pawello87 Год назад
CppCon 2019 - Back to basics: Smart pointers. By Arthur O'Dwyer. What's the point of repeating the same topic three years later?
@treyquattro
@treyquattro Год назад
so that we eventually get it
@johnhsu5459
@johnhsu5459 Год назад
Why does your university offers same classes every year while a recording is available?
@David_Olsen
@David_Olsen 4 месяца назад
Topics on the Back to Basics track are often repeated, but the presenter is always different with the expectation that the talks will be different enough that each of them is useful. Arthur O'Dwyer's and my Smart Pointer talks are more similar than I would have preferred. But Mike Shah's and my Concurrency talks are nothing alike and there are benefits to watching both of them.
@Lalasoth
@Lalasoth Год назад
As already pointed out (yes I know) this same topic was given by Arthur O'Dwyer three years ago. I check these out just in case there's something neat or new discussed. The audio in this video is terrible I couldn't finish watching it.
@paxdei1988
@paxdei1988 Год назад
Audio seems fine to me.
@agentstona
@agentstona 13 дней назад
THIS IS ALL A WASTE OF TIME JUST SWITCH TO RUST OR PYTHON where memory is automanaged for you .... WHY YOU wasting your time attempting to manage stuff that can be automated ....
@mwilby3027
@mwilby3027 Год назад
DId he fr just do an entire presentation reaeding a script
@VictorYarema
@VictorYarema Год назад
Reading a damn good well prepared script.
@treyquattro
@treyquattro Год назад
pretty perfunctory talk. All the huffing and blowing made it seem that Mr. Olsen was doing it under duress. Maybe let someone with a bit more enthusiasm for the subject do it next time?
@daver1964
@daver1964 Год назад
Did it? It could be a health issue, or nerves, or something else.
@debajyotimajumder472
@debajyotimajumder472 5 месяцев назад
I liked the content. Learnt something useful.
@debajyotimajumder472
@debajyotimajumder472 5 месяцев назад
I liked the content. Learnt something useful.
@mrphobos44
@mrphobos44 4 месяца назад
Perhaps he just really wanted to eat those three little pigs. Great talk IMO.
@utilka5415
@utilka5415 4 месяца назад
its smart pointers. It is perfectly understandable to lack enthusiasm on such a basic topic, but someone has to do such entry talks, just so we have an alternative entry point to those zoomer tutorials
Далее
My little bro is funny😁  @artur-boy
00:18
Просмотров 10 млн
I Built a SECRET McDonald’s In My Room!
36:00
Просмотров 17 млн
I Built 100 Homes And Gave Them Away!
09:36
Просмотров 42 млн
Let's get comfortable with SFINAE (C++)
35:55
Просмотров 5 тыс.
CppCon 2014: Mike Acton "Data-Oriented Design and C++"
1:27:46
C++ Code Smells - Jason Turner - CppCon 2019
58:35
Просмотров 77 тыс.
YOTAPHONE 2 - СПУСТЯ 10 ЛЕТ
15:13
Просмотров 120 тыс.
Самый СТРАННЫЙ смартфон!
0:57
Просмотров 35 тыс.
Собери ПК и Получи 10,000₽
1:00
Просмотров 1,7 млн
Best mobile of all time💥🗿 [Troll Face]
0:24
Просмотров 976 тыс.