Smart Pointers in C++ (Stop Using new?)

  Рет қаралды 14,328

Caleb Curry

Caleb Curry

Күн бұрын

Пікірлер: 41
@codebreakthrough
@codebreakthrough Жыл бұрын
I hope this was helpful! Here is the course link I mentioned in the video. New C/C++ course: calcur.tech/c-cpp-newsletter
@vinniciusrosa8284
@vinniciusrosa8284 11 ай бұрын
I do not know yet how to pass unique_ptr as reference to a function. void whatever(...,std::unique_ptr &engine); - - - The call: whatever(engine). It should work, but do not compile.
@andreasguettinger6706
@andreasguettinger6706 Жыл бұрын
As somebody who learned and uses mainly C++98, I'm glad to see videos about these newer C++ concepts I often forget about. 👍
@Nathan00at78Uuiu
@Nathan00at78Uuiu Жыл бұрын
let's go. This is what we need. Been using your lessons for learning anything. So far been great. thanks.
@OlliS71
@OlliS71 3 ай бұрын
shared_ptr is for sharing between threads, i.e. when handling shared data to another thread. Within a thread it's too slow because the control-block is atomically updated.
@agailloty
@agailloty 15 күн бұрын
I have never coded in C++ but lately I started learning Rust, while watching this video I can understand why the ownership/borrow model is powerful paradigm to enforce memory safety. It seems so easy to create bugs in C++
@billbez7465
@billbez7465 11 ай бұрын
Very well done. There were other videos on smart pointers that left me a bit confused. Yours is clear & understandable. Thank you
@lilyscarlet2584
@lilyscarlet2584 2 ай бұрын
handmade hero is a great series on youtube. it uses c++ to make a game from scratch and teaches how to properly manage memory etc. it starts with the windows platform layer and how to do cross platform proper.
@aminramazanifar9743
@aminramazanifar9743 Жыл бұрын
As great as always. Cannot wait to see the course. Thanks!
@sebastianroubert7543
@sebastianroubert7543 Ай бұрын
You’re a beast. Been watching for interview prep. You should start an udemy course!
@古川範和
@古川範和 Жыл бұрын
This is one of the best coding tutorial videos I've watched. Clear, concise and complete. Thank you so much for your great work!
@suryadon947
@suryadon947 11 ай бұрын
Best video for smart pointers Great bro🎉
@xbiohazardx7312
@xbiohazardx7312 Жыл бұрын
This video is very helpful, it's make me figured it out in one video huge thanks!
@MichaelCohen-sb7tw
@MichaelCohen-sb7tw 9 ай бұрын
Thanks Caleb. Very clear examples and explanations.
@skauddy755
@skauddy755 4 ай бұрын
Very clear explanation
@Sluggernaut
@Sluggernaut 8 ай бұрын
11:27 cracked up so hard. I do this all of the time when making videos. Edit: wth? How did that even compile at 13:12. You have to declare the data type when making a shared pointer. Weird.
@michaeldamolsen
@michaeldamolsen 4 ай бұрын
"How did that even compile at 13:12. You have to declare the data type when making a shared pointer." - Since C++ 17 there are deduction guides which allow weak_ptr to take over the type from the shared_ptr and the other way around.
@ArtVandelayInc
@ArtVandelayInc Жыл бұрын
Great tutorial! Thank you
@dwivedys
@dwivedys 7 ай бұрын
Hey good presentation Caleb!
@panjak323
@panjak323 Жыл бұрын
The level of abstraction is on a really akward level. On one hand yeey nice, you don't have to delete pointers manually. On the other hand, if you need to do anything more advanced like cloning, deep and or shallow copy and storing in containers, that requires even more work, knowledge and frustration than managing raw memory directly. I find using smart pointers in very simple situations, where it's not necessary at all and in complicated situations I use raw pointers, just because I hate thinking about the obscure behavior of smart pointers.
@snesmocha
@snesmocha Жыл бұрын
Isn’t that what smart pointers?
@KaiDevvy
@KaiDevvy Жыл бұрын
Smart pointers are a fairly thin wrapper in terms of added complexity. It's not a huge difference in understanding to use them as opposed to raw pointers, and the benefits of clearly defined ownership and automatic deallocation is monumental for the little abstraction. To me though, something that bothers me is just how verbose it is. Going from * to std::shared_ptr is a pain in the ass. Especially when you're making collections of smart pointers or the like
@alirezaarttam3344
@alirezaarttam3344 Жыл бұрын
Awsome. Thanks!
@abhishekkhanchi9105
@abhishekkhanchi9105 Жыл бұрын
Hi Caleb i ran shared pointer example.its giving error . error:smart_p3.cpp:6:34: error: conversion from ‘’ to non-scalar type ‘std::shared_ptr’ requested 6 | std::shared_ptr a= std::make_shared; during compilation . which c++ compiler ur using.. I tried this on g++: gcc version 9.4.0 Please guide Thanks Abhishek
@codebreakthrough
@codebreakthrough Жыл бұрын
You have it should be (5) It looks like it thinks you are trying to use a function for the type because you put the () inside the
@abhishekkhanchi9105
@abhishekkhanchi9105 Жыл бұрын
thanks alot caleb(@@codebreakthrough ) it work for me..
@hiankun
@hiankun 4 ай бұрын
Ownership, lifetime,... After learning some basic Rust, all of these make sense. 😀🦀
@fpldaily5172
@fpldaily5172 Жыл бұрын
hey bro. Please do a java springboot video or course?
@nokia_n-gage
@nokia_n-gage Жыл бұрын
Thanks!
@NoSpeechForTheDumb
@NoSpeechForTheDumb 4 ай бұрын
As a user, you shouldn't be using new/delete anymore. As a library developer, you need it to implement RAII.
@midewestmond9442
@midewestmond9442 Жыл бұрын
Why you using camel case btw and more can you make a video how to setup an editor for c++ development
@sent4dc
@sent4dc Жыл бұрын
4:39 WRONG! 2 memory leaks.
@Brad_Script
@Brad_Script 5 ай бұрын
what I find weird about this code is that you are allowed to return a unique_ptr from a function without using the move function. Is seems that the compiler is smart enough to realize you are moving the unique_ptr from the function to the caller of the function.
@CCCole1
@CCCole1 Жыл бұрын
P.S. Love the content
@赛尼木
@赛尼木 10 ай бұрын
cystall clear!
@hawks3109
@hawks3109 Жыл бұрын
Don't use auto in production code, the rest is good, but auto can make bad assumptions when you start getting into nested data types and other techniques that come up in production code. auto is dangerous and could lead to bad assumptions by the compiler.
@y_x2
@y_x2 3 ай бұрын
Absolutely ridiculous... simply put variable a outside main!
@zohnannor
@zohnannor Жыл бұрын
bro thinks hes mcoding💀💀
Learning C++? Avoid these Beginner Mistakes...
13:47
Caleb Curry
Рет қаралды 6 М.
SMART POINTERS in C++ (for beginners in 20 minutes)
24:32
CodeBeauty
Рет қаралды 106 М.
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
Dynamic Memory with Malloc - Everything you Need to Know
13:51
Caleb Curry
Рет қаралды 10 М.
Allocator
7:31
C++ Data Structures
Рет қаралды 131
C++ Pointers - Finally Understand Pointers
15:56
Caleb Curry
Рет қаралды 220 М.
unique_ptr: C++'s simplest smart pointer
11:54
mCoding
Рет қаралды 46 М.
References in C++ Explained
14:21
Caleb Curry
Рет қаралды 104 М.
Complete Roadmap for Backend Software Engineers (START HERE!)
30:17
Networking in C++
32:50
The Cherno
Рет қаралды 264 М.
are "smart pointers" actually smart?
9:44
Low Level
Рет қаралды 80 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 842 М.
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН