No video

Understanding Static, Stack, and Heap Memory Regions (Examples in C)

  Рет қаралды 40,683

Jonathan Muckell

Jonathan Muckell

Күн бұрын

Understanding how memory in managed is an essential concept in computing. This video explores memory management in the context of the C programming language.

Пікірлер: 67
@Bestcuriosity_1
@Bestcuriosity_1 2 жыл бұрын
Today I found real teacher who can make me love c programming to go deep dive in this field thank you sir for making such beautiful lecture series for us graduate student who got stuck in such hard concepts which was explained by you in easy manner. Huge Respect & love from India
@rotrose7531
@rotrose7531 3 жыл бұрын
Thank you very much, it it difficult to find real c programming tutorials, and u provided a perfect one. Please do not stop
@jonathanmuckell9827
@jonathanmuckell9827 3 жыл бұрын
Thanks for the encouragement! Glad you found this helpful.
@milosb793
@milosb793 2 ай бұрын
I've been learning this on the university for couple of years, and none made me understood this that good as you. Really quality content. Thank you and keep pushing!
@redmundperrz7234
@redmundperrz7234 28 күн бұрын
Finally its crystal clear now for me this topic
@hadiasghari2266
@hadiasghari2266 3 жыл бұрын
Studying CS in Germany and by far you are the best. NO ONE can explain it like you. Shame on my Prof
@yonatanam1
@yonatanam1 Жыл бұрын
Global variables are accessible even from other c modules by using the extern statement. However, if u add static to the global variable, then it is not accessible from other modules. This means that you can define another global static variable with the same name in another module, and it will be separate from the first one which was declared in the other module.
@insoft_uk
@insoft_uk 8 ай бұрын
I use static as well not all the time just as you pointed out it’s actually an important part to know so one knows when it’s needed or not and also used for functions I think he made a big mistake as beginners looking at this video are going to think it’s optional and not necessary at all.
@jakenguyen2584
@jakenguyen2584 2 жыл бұрын
Awesome video, Jonathan. Your slow, detailed explanations really help with drilling the points into my slow brain.
@davidjiang7929
@davidjiang7929 3 жыл бұрын
This is a really good explanation of the variable lifetimes. I came here because programming language analysis class just introduced this, and the textbook did not have good explanations on these concepts.
@wilfredv1930
@wilfredv1930 Жыл бұрын
Your videos about programming are a treasure. thanks a lot!
@BigManTing506
@BigManTing506 2 жыл бұрын
You're so good at explaining concepts!
@onuryorutken5540
@onuryorutken5540 3 жыл бұрын
Great video with great examples!!! Thank you very much.
@andyburris2555
@andyburris2555 Жыл бұрын
Great video for reviewing these concepts. Correct and concise.
@tlwilkinson
@tlwilkinson 2 жыл бұрын
This is the best video online explaining heap and stack.
@ProfessorLinux
@ProfessorLinux Жыл бұрын
I appreciate this series. You are a great teacher.
@jackm.1628
@jackm.1628 2 жыл бұрын
Fantastic explanations, thank you professor!
@douglasthomson2986
@douglasthomson2986 2 жыл бұрын
Great explanation and super useful. Thanks from the UK.
@hubercats
@hubercats 3 жыл бұрын
Thanks for sharing this very clear, helpful video!
@MrOse-nh5pd
@MrOse-nh5pd 2 жыл бұрын
You're truly a good teacher. 👍
@rajeshhariharan7575
@rajeshhariharan7575 2 жыл бұрын
Wonderfully explained; thanks a lot Prof. Jonathan Muckell
@oliverkobing4726
@oliverkobing4726 3 жыл бұрын
What a great teacher!
@pietraderdetective8953
@pietraderdetective8953 3 ай бұрын
Amazing explanation on this memory topic. Well done Sir, well done!
@aminedoughmi8582
@aminedoughmi8582 2 жыл бұрын
excellent course ! keep up the good work
@m.houdeib
@m.houdeib 3 жыл бұрын
Perfectly explained.
@shitinsideyou
@shitinsideyou 10 ай бұрын
Great video, thank you!
@nicolasbourbaki8896
@nicolasbourbaki8896 Жыл бұрын
I wished I had watched this video when I started c coding! Damn job explaining pointers!
@sallaklamhayyen9876
@sallaklamhayyen9876 2 жыл бұрын
Jonathan Muckell you are a wonderful teacher great job thank you so much please continue
@m4tchm4k3r5
@m4tchm4k3r5 3 жыл бұрын
thank you very much, really helpful. You are gold.
@acluster3411
@acluster3411 7 ай бұрын
Great teaching!
@mylogs858
@mylogs858 2 жыл бұрын
Best explanation! And I like the visual aids.
@lunaxiao9997
@lunaxiao9997 Жыл бұрын
Great video! Well explained
@denjiuzumaki4309
@denjiuzumaki4309 24 күн бұрын
nice examples!!
@guliyevshahriyar
@guliyevshahriyar Жыл бұрын
Thank you very much teacher.
@mutalibgozalov7208
@mutalibgozalov7208 4 ай бұрын
Thank U sir, that was helpful
@arslanarslan9432
@arslanarslan9432 2 жыл бұрын
Thank u, you are amazing !!!!!!!
@ii7mdj_353
@ii7mdj_353 8 ай бұрын
Yoooooooooooooooooooo, that makes so much sense now.
@ArunKumar-ll9lo
@ArunKumar-ll9lo 3 жыл бұрын
A very good informative session. Keep it up..
@jonathanmuckell9827
@jonathanmuckell9827 3 жыл бұрын
Glad you liked the video!
@bwzd
@bwzd Жыл бұрын
the stack vs static memory example at 10:00 really made something click for me
@rodolfokey7835
@rodolfokey7835 2 жыл бұрын
Hi Jonathan, thank you for the video. It's very didactic. I have a question: can you access a location in the heap memory (previously allocated with malloc or using "new" in C++) from any function in any class different from the one where the allocation was made? If so, what is the syntax. Thank you
@THawpeek2006
@THawpeek2006 3 жыл бұрын
Nice video with good explanation thanks bro for this
@jonathanmuckell9827
@jonathanmuckell9827 3 жыл бұрын
Glad it was helpful!
@sendlocation8476
@sendlocation8476 2 жыл бұрын
@Jonathan Muckell @Anyone So does that mean when you push the first thing onto the stack. It always occupies the highest memory address first? So it allocates at the very top?
@echoptic775
@echoptic775 2 жыл бұрын
8:00 doesnt static in c mean that its a private variable/function for that file only?
@user-ld8ru7kh6u
@user-ld8ru7kh6u 4 ай бұрын
May i know what is the purpose of storing address in a pointer when anyways the variable is not removed in heap memory?
@spacewad8745
@spacewad8745 2 жыл бұрын
23:00 sizeof is an operator
@Byynx
@Byynx 23 күн бұрын
Since HEAP has unlimited memory space available, is the HEAP inside the process memory region or outside ?
@user-kf1xn1dq9t
@user-kf1xn1dq9t 3 жыл бұрын
Does such system of memory regions applies to all languages (C family, Python, Java, etc.) or only to C specifically?
@jonathanmuckell9827
@jonathanmuckell9827 3 жыл бұрын
The memory regions is are used across programming languages. It's a computing fundamental that is supported by both the operating system and the underlying hardware architecture. Many programming languages try to hide some of the messy details from the programmer (C gives you a lot more control). For example, in Java when you use the keyword "new" you are allocating memory space on the heap. The programmer never needs to free this memory, since Java uses a concept called Garbage Collection that automatically frees memory that will no longer be accessed.
@user-kf1xn1dq9t
@user-kf1xn1dq9t 3 жыл бұрын
​@@jonathanmuckell9827 not exactly what I meant to ask. I meant "is such memory layout/arrangement (stack at the "beginning" of RAM, heap near the "end", and they grow towards each other; static located "outside" of range that memory range between heap and stack) is a standard way of memory representation for all programming languages (regardless is it have manual (C, C++) or automatic (C#, Java) memory management) or such approach specific only to C? For example, if I write char * heap_char_1 = new char; char * heap_char_2 = new char; char * heap_char_3 = new char; char stack_char = "a"; in C++, on computer that have only 100 bytes of RAM, and then print addresses of all four characters into console heap_char_1 would have address 100, heap_char_2 99, heap_char_3 98 and stack_char 0, or something like that?! Or that would be true only in C?
@jonathanmuckell9827
@jonathanmuckell9827 3 жыл бұрын
@@user-kf1xn1dq9t OK - Good question. It is language independent, since it is enforced at the hardware-level. For example, here is an example of the MIPS architecture. If you look on the second page, you can see the documentation for the MIPS processor's memory allocation. Stack grows from a high address down, while the heap grows from a lower address up. This is common practice across various processor architectures. courses.cs.washington.edu/courses/cse378/09au/MIPS_Green_Sheet.pdf
@user-kf1xn1dq9t
@user-kf1xn1dq9t 3 жыл бұрын
@@jonathanmuckell9827 huh, I did not expected that it enforced by hardware. Thank you for clarification. One last question, which is outside of video topic I think. What if I have two programs, HelloWorld and FooBar, running at the same time, probably on different threads, on a single computer. How OS would manage memory for them in this case? Divide memory in half between this two programs? Or place both stacks/heap/static near each others? Or that too specific case that have its own specific rules?
@jonathanmuckell9827
@jonathanmuckell9827 3 жыл бұрын
@@user-kf1xn1dq9t That's another really good question. There are a couple different parts to the question. The first part relates to whether you have separate threads or processes. Threads share a common memory address space. Two threads tend to have 2 different stacks, but will can share other variables in heap or static memory regions. Processes have completely separate addresses spaces and will have independent stacks, heaps, static memory regions. The OS uses a concept called Virtual Addresses to divide the memory space between different processes. More information on that topic can be found here: en.wikipedia.org/wiki/Virtual_address_space
@fc3fc354
@fc3fc354 9 ай бұрын
But can't you update the value of a static variable?I thought it was impossible to change the value of a static variable
@firedragonmangaming2410
@firedragonmangaming2410 2 жыл бұрын
Wait im confused. Does malloc return a void pointer ?
@energy-tunes
@energy-tunes Жыл бұрын
Yes
@user-ui5rx9hg9r
@user-ui5rx9hg9r 3 жыл бұрын
hello
@itsam941
@itsam941 7 ай бұрын
sizeof is an operator not a function
@drogeanunicusor7715
@drogeanunicusor7715 Жыл бұрын
sizeof is not a function, it's an operator
@jonathanmuckell9827
@jonathanmuckell9827 Жыл бұрын
Yes, you are correct. Thanks for the clarification. Additional details can be found here: www.geeksforgeeks.org/sizeof-operator-c/
@swedishpsychopath8795
@swedishpsychopath8795 3 ай бұрын
Explaining this without mentioning the activation record is a waste of time.
@dixztube
@dixztube 7 ай бұрын
Use rust lol
@nononnomonohjghdgdshrsrhsjgd
@nononnomonohjghdgdshrsrhsjgd 2 жыл бұрын
very boring presentation
@osamaragab3325
@osamaragab3325 2 жыл бұрын
then you are in the wrong place ! you could just don't watch the video, this man is a legend !!
Heap (Dynamic) Memory Examples in C
16:02
Jonathan Muckell
Рет қаралды 2,2 М.
Understanding Allocations: the Stack and the Heap - GopherCon SG 2019
21:39
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 31 МЛН
ПОМОГЛА НАЗЫВАЕТСЯ😂
00:20
Chapitosiki
Рет қаралды 21 МЛН
why do void* pointers even exist?
8:17
Low Level Learning
Рет қаралды 349 М.
Stack, Heap, and Static Memory
9:39
Let's Get Rusty
Рет қаралды 47 М.
Heap Memory: malloc, calloc, realloc, and free functions in C
29:42
Jonathan Muckell
Рет қаралды 1,3 М.
Visualizing memory layout of Rust's data types
39:39
Sreekanth
Рет қаралды 12 М.
WHY IS THE STACK SO FAST?
13:46
Core Dumped
Рет қаралды 146 М.
Comparing C to machine language
10:02
Ben Eater
Рет қаралды 5 МЛН
Finally Fix Your Issues With JS/React Memory Management 😤
20:13
Jack Herrington
Рет қаралды 83 М.
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,4 МЛН