Dynamic Memory Allocation in C++

Subscribers:
50,600
Published on ● Video Link: https://www.youtube.com/watch?v=LFwq0cCyazA



Duration: 8:54
477 views
23


C++ Dynamic Memory Allocation. In this video you will learn the difference between static (stack memory) and dynamic (heap memory/free store). The stack memory is allocated at compile time, which is when your program is converted from c++ into machine code. At this time there are checks for syntax errors and how much stack memory is needed. Variables and function calls are stored on the stack memory. Heap memory on the other hand is allocated at run time, and is much larger than stack memory. Because C++ does not have garbage collection, you will need to free any memory allocated on the heap, otherwise there will be a memory leak! To allocate memory on the heap, use the new keyword, and to deallocate/free memory on the heap, use the delete keyword. After freeing the memory, make sure you avoid dangling pointers by assigning the pointer, nullptr.

If you need to review these topics:
Arrays: https://youtu.be/TjIUYNdbmFk
Pointers: https://youtu.be/FSOnAszRFTk
Pointers to Arrays/ Pointer Arithmetic: https://youtu.be/mlTjAmqtNA8
Null Pointers: https://youtu.be/1QMJQ8dCzJQ

C++ Playlist:
https://www.youtube.com/playlist?list=PLnKe36F30Y4ZDNIOZ51sX25pWKQ1pkpTE

Install C++ with VS Code:
https://youtu.be/DMWD7wfhgNY

Subscribe for more coding tutorials 😄!







Tags:
dynamic memory c++
dynamic memory allocation c++
dynamically allocate memory c++
dynamic memory in c++
dynamic memory allocation in c++
dynamically allocate memory in c++
c++ dynamic memory
c++ dynamic memory allocation
c++ dynamically allocate memory
dynamic memory C++
dynamically allocate memory C++
dynamic memory allocation C++
dynamic memory in C++
dynamic allocation memory c++
C++ dynamic memory
C++ dynamic memory allocation
C++ dynamically allocate memory