Difference between revisions of "Advanced C++ Programming Tutorial 6"
From Chilipedia
(→Video Timestamp Index) |
|||
| (6 intermediate revisions by the same user not shown) | |||
| Line 7: | Line 7: | ||
* <code>use_count</code> | * <code>use_count</code> | ||
* How to pass/receive resources when <code>shared_ptr</code> is involved | * How to pass/receive resources when <code>shared_ptr</code> is involved | ||
| − | * Conversion from <code>unique_ptr</code> | + | * Comparing <code>shared_ptr</code>s |
| + | * Conversion from <code>unique_ptr</code> to <code>shared_ptr</code> | ||
* Custom deleter for <code>shared_ptr</code> | * Custom deleter for <code>shared_ptr</code> | ||
| + | |||
=== Part 2 === | === Part 2 === | ||
| − | + | * <code>weak_ptr</code> and <code>lock</code> | |
| + | * The control block | ||
| + | * Monolithic <code>make_shared</code> control block optimization | ||
| + | * Race condition and synchronization | ||
| + | * Resource destruction with monolithic control block | ||
| + | * <code>static_pointer_cast</code> <code>dynamic_pointer_cast</code> <code>reinterpret_pointer_cast</code> <code>const_pointer_cast</code> | ||
| + | * <code>enable_shared_from_this</code> | ||
== Video Timestamp Index == | == Video Timestamp Index == | ||
| − | * [https://youtu.be/ | + | * [https://youtu.be/omw6x5Dz0BM Tutorial 6.1] |
| + | * [https://youtu.be/sv6xVi9fH24 Tutorial 6.2] | ||
== Homework == | == Homework == | ||
=== Part 1 === | === Part 1 === | ||
| − | Identify targets in the [https://github.com/planetchili/Inheritance Memefighter codebase from Intermediate c++] for resource sharing, implement the sharing with <code>std::shared_ptr</code>, and consider/discuss potential downsides to the resource sharing for each instance of resource sharing. | + | Identify targets in the [https://github.com/planetchili/Inheritance Memefighter codebase from Intermediate c++] for resource sharing, implement the sharing with <code>std::shared_ptr</code>, and consider/discuss potential downsides to the resource sharing for each instance of resource sharing. Solution can be found [https://youtu.be/N2CDksFB0Uk here]. |
| + | === Part 2 === | ||
| + | Make a simple announcing class, and then use <code>allocate_shared</code> in conjunction with <code>LocalAlloc</code> from Win32 to create an instance of that class that is managed by a <code>shared_ptr</code> with a monolithic control block. | ||
== See also == | == See also == | ||
Latest revision as of 23:06, 9 November 2019
Share your resources in grand style with shared_ptr.
Contents
Topics
Part 1
- Review of
unique_ptr -
shared_ptrusage scenarios -
use_count - How to pass/receive resources when
shared_ptris involved - Comparing
shared_ptrs - Conversion from
unique_ptrtoshared_ptr - Custom deleter for
shared_ptr
Part 2
-
weak_ptrandlock - The control block
- Monolithic
make_sharedcontrol block optimization - Race condition and synchronization
- Resource destruction with monolithic control block
-
static_pointer_castdynamic_pointer_castreinterpret_pointer_castconst_pointer_cast -
enable_shared_from_this
Video Timestamp Index
Homework
Part 1
Identify targets in the Memefighter codebase from Intermediate c++ for resource sharing, implement the sharing with std::shared_ptr, and consider/discuss potential downsides to the resource sharing for each instance of resource sharing. Solution can be found here.
Part 2
Make a simple announcing class, and then use allocate_shared in conjunction with LocalAlloc from Win32 to create an instance of that class that is managed by a shared_ptr with a monolithic control block.