Pointers and Dynamic Memory in C++ (Memory Management)

Sdílet
Vložit
  • čas přidán 17. 03. 2012
  • An introduction to using dynamic memory in C++.
    Concepts:
    Why we may need to allocate memory dynamically?
    new operator
    heap (free store)
    pointers to reference dynamically allocated memory
    delete operator
    garbage
    dangling pointers

Komentáře • 235

  • @imranabdalla5330
    @imranabdalla5330 Před 6 lety +254

    thanks man, hats off sir.
    I wonder why we pay our universities and end up learning free on CZcams😒

    • @Guest-gy9vp
      @Guest-gy9vp Před 4 lety +15

      Because there are stupid people out there want paper signed by University

    • @rajab4187
      @rajab4187 Před 4 lety +8

      @@Guest-gy9vp hell yeah
      Why job market wants that fucking papr signed by fucking garbage university

    • @EduInquisitive
      @EduInquisitive Před 4 lety +16

      It's because you guys never concentrate during your lecture.

    • @DonSanchezDK
      @DonSanchezDK Před 4 lety +20

      Don't know if you are trolling or for real.. Universities exist to guarantee a certain quality standard, if you have a degree there is a guarantee that you meet those standards and know specific things.. There is no standard for people who learn online, they might be geniuses, but could also be "garbage" programmers.. ;)

    • @ahmedegymed5853
      @ahmedegymed5853 Před 3 lety +2

      @@DonSanchezDK but as an employer you can make interviews or tests ,if the employee pass ....that is a proof he know things necessary for the job...so there goes the purpose of college !

  • @harshitakitchen
    @harshitakitchen Před 4 lety +41

    DUDE I literally got a 100 on my exam because it was based off of memory diagram questions. Thank you!

    • @bdiwy6187
      @bdiwy6187 Před 3 lety +2

      Nice 👍🙂

    • @sharonjoe7535
      @sharonjoe7535 Před 3 lety +1

      @Abhinav Rao LMAO

    • @hemiacetal1331
      @hemiacetal1331 Před 3 lety

      @Abhinav Rao bruh moment

    • @eien7228
      @eien7228 Před 3 lety

      @Abhinav Rao do u think people should work infront of the computer 24/7 to use their programming knowledge?

    • @abhishektiwari7643
      @abhishektiwari7643 Před rokem +1

      @Harsita's Kitchen do you code while cooking?

  • @Neothejew
    @Neothejew Před 7 lety +61

    at 6:48 he crack me up every time.
    Describing all the code I've ever written.

  • @tonyadearaujo
    @tonyadearaujo Před 11 lety +4

    I've been reading Dr. Bjarne Stroustrup's book on Programming and referring to your videos often. I must say that I wouldn't probably be able to go through that complex book if it weren't for your clear, really lucid explanation of concepts. Thank you so much!

  • @BrianBurtner
    @BrianBurtner Před 5 lety

    This video is 7 years old and it is the best explanation I've yet encountered on this topic. Thanks.

  • @ayeyo4081
    @ayeyo4081 Před 4 lety

    This was the best educational video of explaining pointer and dynamic memory. Everything about pointer and dynamic memory is so much clearer now. Cheers !

  • @jasonitsme
    @jasonitsme Před 3 lety +6

    Super clean and easy explanation. Absolute masterpiece if anyone wants to understand pointers, dynamic memory allocation, stack and heap.

  • @chachamarwa6047
    @chachamarwa6047 Před 6 lety +3

    i ‘ve watched many best tutorials but this one made my way clear that i won’t ever forget how stuffs are allocated in the memory. Thanks sir

  • @hassanbentiba4504
    @hassanbentiba4504 Před 4 lety +6

    Just started programming and c++, memory was the first topic that I would first struggle to understand and get my head around and this video really helped :) thank you so much

  • @irem2719
    @irem2719 Před 10 měsíci

    I have never seen anyone explain this more clearly in my life. You are amazing!

  • @g14f
    @g14f Před rokem

    Your efforts are paying off for more than 10 years. This video helped me a lot. Thanks !

  • @cameronsluiter323
    @cameronsluiter323 Před 7 lety +37

    Very informative! Really liked your drawing of the 'heap' and the 'stack'. Made it much easier to understand what is going on.

  • @blakewhitlock2307
    @blakewhitlock2307 Před 4 lety +1

    I was debating dropping my major until i found your videos, thanks for the help/motivation!

  • @Kazner0h
    @Kazner0h Před rokem

    Those illustrations were SOOOOO helpful. Thanks!

  • @War-Cry
    @War-Cry Před 9 lety

    Thank you so much for the tutorial. Dynamic Memory Allocation has been kind of a plateau in my C++ learning, and you explained it very concisely. Very well done.

  • @MyLittleMagneton
    @MyLittleMagneton Před 8 lety +133

    Since C++11 You should not set a pointer to NULL, but rather to "nullptr".

    • @chcipnifasisto
      @chcipnifasisto Před 8 lety +5

      +Peterolen or use 0 and use it in c++1002059

    • @zoranjovanov8564
      @zoranjovanov8564 Před 8 lety +1

      =0 isjust fine anyway.

    • @MyLittleMagneton
      @MyLittleMagneton Před 8 lety +34

      Zoran Jovanov Not really. It was replaced for a reason. Imagine having two functions, void Func(string* aStr) and an overloaded version called void Func(int aNum).
      If I call Func(0) or Func(NULL), Func(int aNum) will be called. But if we call Func(nullptr), then Func(string* aStr) will be called, which we want as we're dealing with pointers.

    • @chcipnifasisto
      @chcipnifasisto Před 8 lety +3

      NULL is just constant of 0 difference is NULL is defined with #define and nullptr is a const variable it was replace just to tell you that you are assigning it to pointer and to avoid some memory leaks :)

    • @zoranjovanov8564
      @zoranjovanov8564 Před 8 lety

      Scias
      yes but i ment only when u delete pointer so it wont be dangling =0 is just fine.

  • @bodduavinash1
    @bodduavinash1 Před 11 lety

    i got the clear idea of what is heap and how to handle new/delete operators and that too dangling pointers and garbage collection. Thanks for this lecture.

  • @JO-ct6dl
    @JO-ct6dl Před 2 lety

    Excellent explanation with the graphics. Please make more videos. Thank you

  • @AnmolSharma293
    @AnmolSharma293 Před 11 lety

    Taking reference from your videos and C++ Primer both, best learning combo ever!

  • @_._lis_._
    @_._lis_._ Před 3 lety

    Woww😲 had been struggling with this topic for months.. well explained..Tysm.. you're awesom!!!

  • @TA-vm8es
    @TA-vm8es Před 10 lety

    This helps me to understand the operations of 'new' and 'delete' . Thanks.

  • @alive4metal453
    @alive4metal453 Před 7 lety

    This is a great video, the drawings really help to make the concepts and idea take concrete form for a begginer

  • @muthu6041
    @muthu6041 Před 5 lety

    He is so simple in explaining complex concepts. thank you

  • @steve018574
    @steve018574 Před 6 lety

    I love the drawings!
    You helped me understand what a stack frame is! Thanks!

  • @alexanderjack8724
    @alexanderjack8724 Před 10 lety

    Excellent video. You really capture the big ideas well.

  • @fireflynahian6878
    @fireflynahian6878 Před 4 lety +7

    finally understood the concept...this video helped me a lot...

  • @icemotion1925
    @icemotion1925 Před 3 lety

    Thank you so much bro! Your drawing and interpretation of heap & stack made me understand the whole thing :D

  • @avanishpatel4936
    @avanishpatel4936 Před 6 lety

    One of the best explained topic I ever seen

  • @hongminwang6747
    @hongminwang6747 Před 8 lety

    Thank you so much. I watched a few of your videos today, and I found them very helpful. Clear and concise, really impressive!

  • @fizzanasir572
    @fizzanasir572 Před 3 lety

    Such an amazing amazing amazing amazing amazing amazing tutorial...hats off

  • @michaelwright8576
    @michaelwright8576 Před 3 lety

    Wow. explained in such simple terms. Thank you so much.

  • @jiroquijano
    @jiroquijano Před 11 lety

    Thanks for the video! It's a lot easier to program codes in c++ using memory allocation with your explanation visuals in mind! Thanks a lot! :D

  • @ersandy4u
    @ersandy4u Před 9 lety

    Excellent for someone working closer to the hardware and memory!! Great video. Keep it up

  • @mukhtarthechosenone7851

    Thank you very much.
    You really helped me. May God guide you and increase your knowledge .

  • @FluffyNinjaUnicorn3Gaming

    Very informative video! Thank you so much!

  • @RockSmithStudio
    @RockSmithStudio Před 11 lety

    You are incredible! Great presentation! Keep it up!

  • @lahiru1k
    @lahiru1k Před 11 měsíci

    very precise and informative!!~ thank you so much!!

  • @louischvs9395
    @louischvs9395 Před 6 lety

    The best video I've ever watched about pointers

  • @oaomybb
    @oaomybb Před 2 lety

    very clear clarification. Thanks man

  • @ASDFG856
    @ASDFG856 Před 9 lety +8

    best pointer explanation ever :D

  • @anoobis8674
    @anoobis8674 Před 6 lety

    Very informative video! Keep it up.

  • @henrikaskancys4956
    @henrikaskancys4956 Před 4 lety

    Short and informative, thank you!

  • @parasbhanot
    @parasbhanot Před 12 lety

    best c++ fundamental videos on youtube

  • @badis23
    @badis23 Před 7 lety

    thank you so much I never get to understand pointer as I did this time, thank you again

  • @rajcodes100
    @rajcodes100 Před 3 lety

    This was crystal clear .Thanks

  • @amiralihosseinzadeh7336
    @amiralihosseinzadeh7336 Před 2 lety +1

    the best 13 minutes of my life

  • @rogerhunter313
    @rogerhunter313 Před 3 lety

    This was a great explanation. Thank you!

  • @AyaNori
    @AyaNori Před 2 lety

    great job! thanks so much for making this video :) helped me with my homework

  • @BrianVandrian
    @BrianVandrian Před 11 lety

    Thanks for the video its NUTS & BOLTS :). I am trying to learn how to make a program and everyone says C++ is powerful because of memory management, but now that I am learning it they keep getting away from the nuts and bolts and pretty soon everyone is talking about packaging everything into things already programmed in other things... boxes within boxes and which box to use... Before too long I don't even know what nuts and bolts are actually in the boxes or anything from anything. So thanks

  • @mohammedkashifqamer8665

    Thanks for such an easy explanation

  • @purushothamreddy4453
    @purushothamreddy4453 Před 7 lety +1

    Awesome explanation

  • @marianaql
    @marianaql Před 6 lety

    I loved your explanation. Thank you!

  • @susie5245
    @susie5245 Před 5 lety

    Wow great video! I completely get it now :) Doing a quick review, haven't touched this material in a while haha

  • @ReelLearning
    @ReelLearning  Před 12 lety +2

    I removed a comment by mistake. Apologies to the user that left the nice comment. I had replied "Thanks!" to your comment under my other account and wanted to reply under my ReelLearning account. Deleting my comment, deleted your comment, for some reason.

  • @yapayzeka
    @yapayzeka Před 4 lety

    a legendary explanation. thank you sir.

  • @MrTomro
    @MrTomro Před 5 lety

    Amazing explanation. Thanks

  • @francisDr4ke
    @francisDr4ke Před 4 lety

    very great explaination. thank you

  • @philip-neridzathor8115

    Great explanation.

  • @morriskeller
    @morriskeller Před 3 lety

    excellent explanation!

  • @BelowHorizon
    @BelowHorizon Před 10 lety

    I love your tutorials. You explain thing soooooooooooo clear. Thank you soooooooooooooooooooooooo much.

  • @aribakodes5453
    @aribakodes5453 Před 4 lety

    Agree, finally understood the concept

  • @lizhu8548
    @lizhu8548 Před 4 lety

    The "garbage", i guess is called "memory leak". Good video!

  • @mad8ry
    @mad8ry Před 7 lety

    Thank you so much for your effort man! your doing such a great job...
    I have only one question, is there any way to get your notes for the videos you ?

  • @FriedaNgaharjo
    @FriedaNgaharjo Před 11 lety

    Thank you! You really explained it well and it helps me a lot in studying :)

  • @treasure2387
    @treasure2387 Před 11 lety +2

    The stack memory is managed by the program/compiler
    Dangling pointer = pointer that points to something that no longer exists.
    you can assign a dangling pointer the value NULL or 0
    When a function exits its memory on the stack is deleted.

  • @foreveralone4813
    @foreveralone4813 Před 8 lety

    Thank you so much for offering high quality tutorials!

    • @faris899
      @faris899 Před 8 lety

      +Forever Alone Studying for the CS final? lol

    • @foreveralone4813
      @foreveralone4813 Před 8 lety

      What?

    • @KG_BM
      @KG_BM Před 8 lety

      +Ferris Bueller yes, this is part of my last assignment and will make up most of the final

  • @Quancept
    @Quancept Před 4 lety

    Thanks man, really good explanation!

  • @1qaribullah
    @1qaribullah Před 7 lety

    Great explanation. Is it possible to find size of the reserved memory for a specific variable in heap? For stack, it is sizeof() but what would be the case for heap????

  • @vichitt1
    @vichitt1 Před 11 lety

    Thank you for explaining it so well!!!

  • @Yh-gu3cw
    @Yh-gu3cw Před 7 lety

    Thank you. I understood everything you said.

  • @NoobcraftReker
    @NoobcraftReker Před 10 lety +3

    Thank you so much! I finally understand why pointers are useful! I have been facepalming over them ever since I first read about them.

  • @jenishghale6672
    @jenishghale6672 Před 8 lety

    Very Useful. Thankyou

  • @devenmhatre727
    @devenmhatre727 Před 6 lety

    my cpp dll is creating a dynamic array, and the call from exe is getting back the pointer pointing to the dynamic array. The problem is that the returning pointer is null every time. Even though the pointer is pointing to a array in the dll.
    How can we solve this problem.

  • @yayaskurt
    @yayaskurt Před 7 lety

    What happens if u store p on a vector, then creates a new p and stores it in the vector, can u access both?

  • @rosna_773
    @rosna_773 Před 6 lety

    You are just awesome! thank you so much!

  • @raihanrony1810
    @raihanrony1810 Před 3 lety

    so can I write
    int *p = new int;
    *p=5;
    p = NULL;
    and skip ( delete p ; ) line like that ?

  • @maxim25o2
    @maxim25o2 Před 3 lety

    Greate explanation.

  • @akhtarabbas5760
    @akhtarabbas5760 Před 6 lety

    outstanding sir.

  • @Ronaldo637_
    @Ronaldo637_ Před 12 lety

    really nice article about memory

  • @T-She-Go
    @T-She-Go Před 4 lety

    Hi :) thank you for such a wonderful lesson.
    Just a quick question: is there a to get *p to point back to memory address 500? Like say for instance we point to 500 (after we allocated space at address 500) and then we point to 700 ((after we allocated space at address 700). Can pointer p point back to 500?

  • @CellarPhantom
    @CellarPhantom Před 11 lety

    Soo, if I make normal variables I do not need to delete them right? And I think it is hard to understand when I should make variables on the heap and when not to. It's easier to always do 'normal' variables.

  • @uruta09
    @uruta09 Před 3 lety +1

    4:31 That voice crack though haha

  • @peksn
    @peksn Před 4 lety

    Holly shit you explaint it like no other, literally 15 min and I understand it all now! Thank you!! :D

  • @MarijnKonings
    @MarijnKonings Před 11 lety

    Thanks, this was a really good explenation.

  • @naython13
    @naython13 Před 5 lety

    Newbie here, why would you use a variable in the heap and not the stack?

  • @ImaginaryHuman072889
    @ImaginaryHuman072889 Před 7 lety

    this video explains alot. however, as a beginning, I still have a few questions.1. Variables stored in the stack DO have variable names and variables stored in the heap DO NOT have variable names, correct?2. What is the advantage/disadvantage of storing variables in the stack vs. in the heap?3. This is probably a stupid question, but why is it necessary to have a stack and a heap? Why can they not be considered one and the same? Then pointers would not be necessary?

  • @krupt5995
    @krupt5995 Před 6 lety

    So if heap memory cant cause only program polution by garbage and other problems why are we using it?

  • @diverseprogrammer18
    @diverseprogrammer18 Před 5 lety +1

    OOOOHHH MYYY GAAAADD! Pointer's too simple now that I learned it from u

  • @ricardodelgado9125
    @ricardodelgado9125 Před 7 lety

    thanks friend greetings from Colombia :-)

  • @gbrain12345
    @gbrain12345 Před 11 lety

    Very good, i like it much !

  • @schifferay
    @schifferay Před 4 lety

    really really really helpful! thank you!

  • @BeansEnjoyer911
    @BeansEnjoyer911 Před 2 lety

    Great video

  • @narutosupernova
    @narutosupernova Před 11 lety

    Just wanna ask to use memory allocation did you use new or malloc, because it makes me confuse with java

  • @nelsonmei9527
    @nelsonmei9527 Před 6 lety

    I finally understand this concept

  • @willbecker7100
    @willbecker7100 Před 3 lety

    Trying to change how memory allocates In a game for a mod. How would I do that?

  • @hassansoleimani1061
    @hassansoleimani1061 Před 6 lety

    Very very good.
    Thanks

  • @AlphaCentauriVirgo
    @AlphaCentauriVirgo Před 11 lety

    Yea nullptr uses in C++ from the book. Very good video very clear. Better than the book.

  • @AlbertoRivas13
    @AlbertoRivas13 Před 4 lety

    This is great man thanks a lot

  • @nirmalraj4167
    @nirmalraj4167 Před 6 lety

    I have one nooby doubt.. What if we assingn pointer p value as,
    int x = 5;
    int* p = &x;
    cout

  • @SunSay
    @SunSay Před rokem +1

    History
    In 1955, Soviet computer scientist Kateryna Yushchenko invented the Address programming language that made possible indirect addressing and addresses of the highest rank - analogous to pointers. This language was widely used on the Soviet Union computers. However, it was unknown outside the Soviet Union and usually Harold Lawson is credited with the invention, in 1964, of the pointer.[2] In 2000, Lawson was presented the Computer Pioneer Award by the IEEE "[f]or inventing the pointer variable and introducing this concept into PL/I, thus providing for the first time, the capability to flexibly treat linked lists in a general-purpose high-level language".[3] His seminal paper on the concepts appeared in the June 1967 issue of CACM entitled: PL/I List Processing. According to the Oxford English Dictionary, the word pointer first appeared in print as a stack pointer in a technical memorandum by the System Development Corporation.
    en.wikipedia.org/wiki/Pointer_(computer_programming)#History