Dynamic Memory Allocation in C++

Поділитися
Вставка
  • Опубліковано 19 бер 2024
  • 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: • Arrays in C++
    Pointers: • Pointers in C++
    Pointers to Arrays/ Pointer Arithmetic: • C++ Pointers and Arrays
    Null Pointers: • C++ Null Pointers
    C++ Playlist:
    • C++ Programming Tutorial
    Install C++ with VS Code:
    • How to set up C++ in V...
    Subscribe for more coding tutorials 😄!

КОМЕНТАРІ •