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

preview_player
Показать описание
---

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

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.
---

#cppcon #programming #coding
Рекомендации по теме
Комментарии
Автор

THIS GUY! ... every talk he did i watched so far is worth its time in gold

violetashopova
Автор

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!

coolwinder
Автор

Excellent talk, thank you! Appreciate always revisiting some fundamentals.

qksuna
Автор

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.

Bolpat
Автор

Great talk - thank you for the fundamentals here!

acur
Автор

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

Roibarkan
Автор

Wonderful video!!! Very well explained covering lots of issues with usage as well.

aprasath
Автор

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?

Bolpat
Автор

The variable length arrays in the examples are ok?

oraz.
Автор

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.

Roibarkan
Автор

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!

flocela
Автор

9:29 unique pointer as member of class

nhanNguyen-wofy
Автор

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?

cunningham.s_law
Автор

I'd argue that the first two examples don't need smart pointers.. what's wrong with std::vector??

rutabega
Автор

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

leili
Автор

CppCon 2019 - Back to basics: Smart pointers. By Arthur O'Dwyer. What's the point of repeating the same topic three years later?

pawello
Автор

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.

Lalasoth
Автор

DId he fr just do an entire presentation reaeding a script

mwilby
Автор

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 ....

agentstona
Автор

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?

treyquattro