new & delete Operators For Dynamic Memory Allocation | C++ Tutorial

new & delete Operators For Dynamic Memory Allocation | C++ Tutorial

Portfolio Courses

2 года назад

31,581 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@jojo-2059
@jojo-2059 - 24.08.2024 12:20

Let's say you have a 2D pointer array of objects and the pieces in the array is dynamically allocated. Why would it be a terrible idea to "delete" a specific entry, arr[i][j] and attempt to assign nullptr afterwards to that entry? I attempted that with a specific piece of code in my chess game in the one case it caused a segfault and the other case it functioned seemingly fine. I am new to C++ so this is a bit confusing.

Ответить
@guillaumemz
@guillaumemz - 03.08.2024 16:37

Please do NOT use new/delete to dynamically allocate/deallocate memory in production code. Use smart pointers (std::unique_ptr, std::shared_ptr with the helper functions std::make_unique and std::make_shared) instead. By the way, avoid using namespace std; and use nullptr instead of NULL.

Ответить
@msk1754
@msk1754 - 30.06.2024 06:35

Thanks for making video!
If base adress is 0x0001,
ptr_to_ have to be allocated 0x0001+ sizeof(int)?

Ответить
@BelegaerTheGreat
@BelegaerTheGreat - 31.03.2024 22:21

My God, if I had just watched this 15 minute video before starting my project it would eliminate like 2 hours of confusion...

Ответить
@张武王
@张武王 - 20.03.2024 08:24

Just out of curiosity, what is the font used for coding in this video? It looks quite pleasant to me.

Ответить
@Ivy891
@Ivy891 - 28.02.2024 17:41

amazing video !

Ответить
@lexdose4104
@lexdose4104 - 13.01.2024 08:26

Ive been learning C++ as a 1st year CS student from around 5 months now and Im currently dealing with pointers from my book resources. I was very confused about the concept of new and delete operators and was wondering why I should use them and now Im starting to understand their functions and how important they are on memory management, thank you so much!

Ответить
@mouli4867
@mouli4867 - 02.01.2024 11:20

Thank for this tutorial. But I couldn’t find out a tutorial of yours on placement new. Please can we have a tutorial on that whenever you have time. Thank you once again.

Ответить
@imveryhungry112
@imveryhungry112 - 11.12.2023 23:30

im too dum to understand any of this

Ответить
@YeabsiraAlemu-bx9si
@YeabsiraAlemu-bx9si - 01.12.2023 10:52

Fantastic

Ответить
@masihaahmadi7663
@masihaahmadi7663 - 02.11.2023 08:32

great

Ответить
@mrtom-a-hawk6732
@mrtom-a-hawk6732 - 14.10.2023 22:56

The clarity of this video is beyond incredible. Fantastic work!

Ответить
@dishmaster4140
@dishmaster4140 - 19.09.2023 05:01

From the bottom of my heart, thank you SO MUCH for this. I have been having the hardest time understanding pointers because no resource I had found was hitting quite the right spot on why we should care about pointers, but you did it.

Thank you for taking the time to demonstrate the memory allocation and your attention to discussing that side of things. I have been pulling my hair out over this, and I cannot tell you how overjoyed I am to have found this video.

Ответить
@sournois90
@sournois90 - 20.05.2023 23:23

are you an angel? ive been trying to understand this for days and you're the only one that made it make sense

Ответить
@CPPLover-df9zw
@CPPLover-df9zw - 11.05.2023 00:24

Would it not be better to declare the big_array pointer out of the try-block and initialize it with a nullptr? After the allocation happens and the main terminates, this is going to result in a memory leak.

Ответить
@chickenmadness1732
@chickenmadness1732 - 05.04.2023 18:33

I love the commented diagram you made below the code. Really helped a bunch of stuff click.

Ответить
@mihaibozian
@mihaibozian - 26.01.2023 12:27

best explanation about dynamic mem allocation

Ответить
@uclocnguyenvo422
@uclocnguyenvo422 - 13.01.2023 08:10

oh shit this tutorial is so good -_- u deserve millions of subscribers

Ответить
@ivans7
@ivans7 - 28.12.2022 00:55

What is the editor name?

Ответить
@stonedcodingtom9097
@stonedcodingtom9097 - 09.12.2022 20:11

Thanks!

Ответить
@muhammadluqman3452
@muhammadluqman3452 - 22.07.2022 19:36

great playlist , you are a hidden gem!

Ответить
@korngsamnang
@korngsamnang - 12.06.2022 15:05

int x = 5;
int *y = &x; //s1
int *y = new int(x); //s2
Sir, what is difference between s1 and s2 ?

Ответить
@i-yusuf
@i-yusuf - 18.05.2022 16:42

Hey man, thanks for making c++ playlist, Which IDE are you using ?

Ответить
@Vichained
@Vichained - 18.05.2022 16:36

didnt you cover this topic in previous videos?

Ответить