Stack vs Heap Memory in C++

preview_player
Показать описание


malloc links:

Thank you to the following Patreon supporters:
- Dominic Pace
- Kevin Gregory Agwaze
- Sébastien Bervoets
- Tobias Humig
- Peter Siegmund
- Kerem Demirer

Gear I use:
-----------------

Рекомендации по теме
Комментарии
Автор

Hope you guys enjoyed the video! A few notes:
- to be clear, each program/process on our computer has its own stack/heap
- each thread will create its own stack when it gets created, whereas the heap is shared amongst all threads

TheCherno
Автор

You are insanely efficient in explaining complex material, wow..., kudos.

dubrider
Автор

How is it that none of my teachers explained any of this during my whole bachelors degree.... this is brilliant! Thank you so much!

rawali
Автор

I’m a Software Engineer, and my first SWE position was as a C++ developer which I learned predominantly from Cherno. I have an EE education, but I learned more from Cherno watching YouTube than I did in my Intro to C++ and Data Structures and Algorithms in C++ sequence in college. The Cherno is legit folks, but if you really wanna learn, you gotta start at the beginning of the playlist and go straight through watching EVERY VIDEO and coding along. C++ can be a frustrating language to learn, but if you learn C++ first, it’s cake learning ALL OTHER C-like languages. You’re the man Cherno!

Earth-Worm-Tim
Автор

I like how you show why something is “expensive” or not very optimal instead of just saying it. You actually open the memory view or disassembly which is super useful! Thanks for the videos, they’re amazing!

CaffeineForCode
Автор

*My takeaways:*
1. Both stack and heap memory are in RAM 0:47
2. How to allocate stack and heap memory 2:55
3. Stack memory allocation *stacks* data in the memory *in a row* and it is very fast 4:45
4. Heap memory allocation doesn't 7:49
5. Heap memory allocation needs to be freed manually by using "delete", whereas stack memory allocation is freed once the code is out of the current scope 8:47
6. How heap memory, "new" and "delete" work 10:27, allocating memory on the heap is slow

leixun
Автор

I think this is my favorite video so far. I always wondered about the stack and heap differences. This is such a good explanation!

TokisanGames
Автор

hey cherno, your explanation of stack vs heap is amazing, no other youtube has evern been able to explain like this. ive come across heap and stack so many times but never got to really understand untill i watched your video today. thanky you so much!

dongyoungkim
Автор

This stuff is all great man. All of your C++ videos have been amazing so far.

donha
Автор

This is by far the most complete lecture/tutorial whatever, I have seen in a very long time (possibly ever). You explained everything very clearly, demonstrated and tested them, yet did that all in 20 minutes. I am honestly surprised that this video doesn't have hundreds of thousands of views because you deserve that. Wish you the best!

MuhsinFatih
Автор

This is A+ content. For someone trying to learn to code there is a lot here and I will be re-watching this a couple of times and playing with the memory view in Visual Studio. Thanks.

jammerbammer
Автор

Finally, you are back, your video always great, thank you !!

ZzBiazZ
Автор

The stuff that I learned in this one single video is actually insane. like, I knew about most of the stuff that he said, but since all of it was taught to me over various courses, and bits and pieces at a time, I never really could figure out how it all fit in together...This such a wonderful explanation!!
All of it is starting to kind of make sense now....damn lol

mubin
Автор

Great video! Heap memory is a really complex topic.... It took me a long time to figure out how it works when I was writing my own memory manager! Thanks a lot for this!😃

proton
Автор

Very clear and easily accessible explanation, even the explaining with asssembler was just really supporting understanding.

maxbardelang
Автор

For all C# developers: "new" does not mean, that it will be allocated on the Heap (for C# program)
MyClass c = new MyClass(); // Allocated on the Heap
MyStruct s = new MyStruct(); // Allocated on the Stack (in most cases)
That doesn't mean that structs are ALWAYS allocated on the Stack! Just most of the times. It depends.
Read about "stackalloc" keyword and about "Span" and "ReadOnlySpan". They are great!

igorthelight
Автор

This video helped me a ton with interview questions, thank's so much!

ifeekesifeekes
Автор

This video is really easy to understand!! I didn't know that allocating memory in heap is such a heavy work, and didn't know why it's heavy. You showed me the way to ensure the reason, looking into the assembly code. I'm gonna consider using Visual Studio...

rika
Автор

MAGISTER DIXIT...!
I am no programmer but I have had basic lessons in C almost 30 years ago and now I am strugling to master at least the basics of C#, which I find sometimes a bit confusing and with a lot of rules. Sometimes I get some comfort watching basic C ++ videos, especially those that are very well explained and that go right to the point like yours.

marioseis
Автор

Thank you for this video. I have been confused about stacks and heaps. You helped me so much. Time to practice 🙌🏽🙌🏽

sayeddileri