C++ Advanced 01c: Pointers and Dynamic Memory Allocation + Memory Leaks!
(Chapter links below)
In this video, we'll show you how to dynamically allocate memory while your program is running, instead of when it is compiled, to save memory and reduce the size of your executable.
Video 01b (Previous): More Pointers and Arrays: https://youtu.be/mE-NjYNjj2c
Video 01c (Next): Dynamic Arrays of Puppies: https://youtu.be/2ljXcPLUyJw
00:00 Dynamic Memory Allocation (Linux/Windows)
06:02 Memory Leaks in your program (Linux/Windows)
16:14 Memory leak tools on Windows (Dr. Memory)
Dr. Memory Download link: https://drmemory.org
Windows
----------------
Setup your Windows Project for Dr. Memory (within Eclipse - Windows Only):
1) Right click on your project from within Eclipse
2) Select Properties
3) Expand C/C++ Build
4) Click Settings
5) Under GCC C++ Compiler, click Miscellaneous
6) At the end of Other Flats, enter " -gdwarf-2" without the quotes
7) Click Apply, then click Rebuild Index
8) Under MinGW C++ Linker, click Miscellaneous
9) In the Linker flags entry field, type "-static-libgcc -static-libstdc++" without the quotes
10) Click Apply and Close
11) Click Project, Clean, Clean
12) Rebuild your application, now drag it to the Dr. Memory Icon on your desktop
Command to enter in the terminal/power shell if you don't use Eclipse:
g++.exe --static-libgcc --static-libstdc++ -gdwarf-2 -o main.exe main.cpp
(This command assumes you have installed the g++ compiler and the path to that compiler is part of your PATH varaible)
Command to start Dr. Memory from the command line: (Windows Only)
drmemory.exe -- c:\path\to\my.app.exe
To enable Dr. Memory from a Visual Studio Code project (Windows Only)
1) Create your folder project/source file (ex: main.cpp)
2) Build your program and test it (this will create your .json file needed for building/running)
3) From the menu, click Terminal - Configure Tasks
4) Click the compiler task (ex: C/C++: g++ build active file, compiler: c:\msys64\usr\bing++.exe)
This will open the tasks.json file
5) Under the args section, change -g to -gdwarf-2
You can do that for every single build task in the tasks.json file
Just replace -g with -gdwarf-2 in all args sections of the file
6) Close/Save the tasks.json file and rebuild
Linux (and Linux on Windows Subsystem for Linux - WSL)
-----------------------------------------------------------------------------------------------
Installing Valgrind
(This assumes you have already installed the build-essential package)
1) Open a Terminal
2) Type: "sudo apt update" without the quotes
3) Type: "sudo apt install valgrind" without the quotes
Running Valgrind from the command line:
1)Compile/Link your app:
ex: g++ -ggdb --static-libgcc --static-libstdc++ -o main main.cpp
2)Run Valgrind:
valgrind ./main
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «C++ Advanced 01c: Pointers and Dynamic Memory Allocation + Memory Leaks!», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.