Your Computer is Lying To You (Virtual Memory)

  Рет қаралды 16,233

Jacob Sorber

Jacob Sorber

Күн бұрын

Patreon ➤ / jacobsorber
Courses ➤ jacobsorber.thinkific.com
Website ➤ www.jacobsorber.com
---
Your Computer is Lying To You (Virtual Memory) // New programmers usually don't understand how memory works. Addresses are addresses, right? This video gives a short introduction into what virtual memory is and-at a high level-how it works.
***
Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.
About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.
More about me and what I do:
www.jacobsorber.com
people.cs.clemson.edu/~jsorber/
persist.cs.clemson.edu/
To Support the Channel:
+ like, subscribe, spread the word
+ contribute via Patreon --- [ / jacobsorber ]
Source code is also available to Patreon supporters. --- [jsorber-youtube-source.heroku...]

Пікірлер: 40
@umpoucosobreconhecimentos
@umpoucosobreconhecimentos 2 жыл бұрын
I am learning a lot with your low level code explanation videos. It is very useful to me. Thank you very much
@JacobSorber
@JacobSorber 2 жыл бұрын
You are welcome! Glad I could help.
@olegfare4625
@olegfare4625 2 жыл бұрын
you are hands down the best youtuber when it comes to explaining C coding , memory and computer science overall for beginners like me! the clearest explanation possible! huge thanks from Russia
@tranqilo6453
@tranqilo6453 2 жыл бұрын
Best Comp Sci professor I have never paid for, thanks for sharing your knowledge sir.
@KangJangkrik
@KangJangkrik 2 жыл бұрын
You paid him with ads, by the way
@georgecop9538
@georgecop9538 2 жыл бұрын
Yeah, OSes provide a lot of abstractions *eg. device drivers* from the core functions like inb(),outb() or memset()
@monad_tcp
@monad_tcp 2 жыл бұрын
4:22 mostly, the system tries to do that, the hardware MMU helps a bit, but it eventually fail, and the machine can crash, although rarely
@mr.mirror1213
@mr.mirror1213 2 жыл бұрын
Iirc, the operating system dispatches page tables unique to a process and when ever you access a memory, the mmu walks the page table to give you the data
@foadsf
@foadsf 2 жыл бұрын
do you got Twitter? I tried searching for you with no avail. just wanted to let you know that you are awesome man. I love your C videos. please keep up the good work. 🖖
@Gauthamphongalkar
@Gauthamphongalkar Жыл бұрын
Hi Jacob, Big fan of you! I have question if address are virtual then why we bothering about memmove of address overlapping.. it will be translated by MMU right?
@smrtfasizmu6161
@smrtfasizmu6161 2 жыл бұрын
I didn't notice that compiler always puts variables on the same addresses so I always wondered how buffer overflow attacks are done. I have watched some video about it and I never understood how you know with what number to overwrite the place on the stack where the previous instruction pointer is.
@starc0w
@starc0w 2 жыл бұрын
Top! Thanks!
@hakimcherfi217
@hakimcherfi217 2 жыл бұрын
Awesome video !
@raghavsrivastava2910
@raghavsrivastava2910 2 жыл бұрын
How are you running macOS and Linux together, are you using a remote machine? Also why the compiler chooses address for x so big, it can even choose something like 0x1 or 0x2 or whatever (I know choosing such big addresses doesn’t make the os allocate tonnes of memory [learned from one of your video]). Thanks in advance, amazing video.
@LFSDK
@LFSDK 2 жыл бұрын
A program’s memory is divided into segments which have pretty standard placememts in virtual memory. To make sure null pointers cause segfaults the area around zero (small addresses) is left unallocated. And you lose nothing by using big addresses rather than small addresses since virtual memory mapping (stored in tables in memory managed by the OS) also divides the address space (both virtual and physical) into pages that make small and high addresses the same. So, using bigger numbers is really just a convention that we stick to.
@JacobSorber
@JacobSorber 2 жыл бұрын
What LFalch said. And, I'm running macOS natively, and Linux on a virtual machine, using vagrant/virtualbox.
@raghavsrivastava2910
@raghavsrivastava2910 2 жыл бұрын
Thank you @LFalch , @Jacob Sorber ❤️
@tanchienhao
@tanchienhao 10 ай бұрын
Awesome video
@funkykong9001
@funkykong9001 2 жыл бұрын
What Linux distro are you using? On my Ubuntu 21.10, the address of x does change every run. However, if I build with "-Wl,--no-pie", then yes, it's a static address each run, so I think your results are highly dependent on what default compiler/linker options your Linux distro is using.
@JacobSorber
@JacobSorber 2 жыл бұрын
I was using Ubuntu 20.04.3. But, yes, good point. It's not a Linux/macOS thing as much as an OS/compiler/linker thing. Those were just the two environments that I had handy.
@YouBuyWeRush
@YouBuyWeRush 2 жыл бұрын
Yeah but what if you need to know the actual address? What then?
@anthonynjoroge5780
@anthonynjoroge5780 2 жыл бұрын
Why would you want to know the actual address? Under what circumstance?
@LFSDK
@LFSDK 2 жыл бұрын
The physical address? In the cases, where you’d need that, you probably aren’t using virtual memory anyway. On a normal personal computer, there’s really no way for to find out since the OS manages the pages that map virtual and physical address space. In systems, where some of the physical memory address space is actually some other device, you’re probably not dealing with virtual memory anyway and so it’s out of scope for this video.
@YouBuyWeRush
@YouBuyWeRush 2 жыл бұрын
@@anthonynjoroge5780 I don't know. But are you saying there are absolutely ZERO use cases in which you have to know the actual address?
@bamberghh1691
@bamberghh1691 2 жыл бұрын
Read from /proc//pagemap. Sudo is required though.
@rmaster934
@rmaster934 2 жыл бұрын
Probably you don't need it since it's abstracted away on OS level. When you NEED to know, you're pretty much interacting with hardware directly, no OS, no virtual memory and stuff. I used physical memory addresses when I was hacking Gameboy games where there's no OS at all, and you get direct access to Video RAM, IORAM, ROM addresses etc.
@arrahul316
@arrahul316 2 жыл бұрын
Great!!!!!!!!!!!!!!!!
@dwaynestgeorge2558
@dwaynestgeorge2558 Жыл бұрын
Thanks
@mehregankbi
@mehregankbi 2 жыл бұрын
my question is, why doesn't realloc always return the same pointer? so let's say we need 2MB of memory but there is not a chunk available on our physical memory, so our data is moved further. but all that needs to be changed is the virtual address to physical address map. similarly, this could be done for the variables in stack too. right?
@wumi2419
@wumi2419 2 жыл бұрын
I'd assume virtual to physical address maps are using page addresses or even bigger blocks, so it's basically impossible to move small memory blocks. I also don't know much about structure of processor and/or memory, which i will hopefully learn more about later.
@ohwow2074
@ohwow2074 2 жыл бұрын
Yes. Now my question too. Why doesn't OS return the same address to the program every time realloc is called??
@DaNinjasDen
@DaNinjasDen 2 жыл бұрын
Likely because it couldn't fit in the virtual address space. If you have an allocation at 0x4 of size 2 and an allocation at 0x6 of size 2, then if you realloc the 0x4 alloc to a size of say 10 it would be overlapping with the other alloc if it used the same base address,so it returns a different address
@mehregankbi
@mehregankbi 2 жыл бұрын
@@DaNinjasDen oh thx for the explanation. it makes sense now. since pointer arithmetics are done on the virtual address, you have to change the virtual address too.
@ohwow2074
@ohwow2074 2 жыл бұрын
@@DaNinjasDen let's assume that there is no data in 0x6. Then if we want to extend the block that starts at 0x4 by another 2 bytes (total size will be 4) then will the OS decide to keep the original block in its place and add the required 2 bytes to it by allocating 0x6 and 0x7 to the original block??
@JusticeNDOU
@JusticeNDOU 2 жыл бұрын
source code available during office hours at , that was what came to mind when listening to this, i cant seem to figure out why , can someone help ?
@krumpy8259
@krumpy8259 2 жыл бұрын
This is so low level that I missed bad paintings for better understanding
@XenoTravis
@XenoTravis 2 жыл бұрын
Jokes on it, I manipulate the crap out of it everyday! We have a very abusive relationship
@xrafter
@xrafter 2 жыл бұрын
Fing OSs lying to us all the time🤬
The Multiple Paths through Embedded Systems
29:04
Jacob Sorber
Рет қаралды 10 М.
But, what is Virtual Memory?
20:11
Tech With Nikola
Рет қаралды 218 М.
I CAN’T BELIEVE I LOST 😱
00:46
Topper Guild
Рет қаралды 49 МЛН
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 12 МЛН
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 2,5 МЛН
How to make memory read-only in your C programs.
12:57
Jacob Sorber
Рет қаралды 19 М.
What's Virtual Memory? - Computerphile
22:40
Computerphile
Рет қаралды 174 М.
How to Write Function-Like Preprocessor Macros (C example)
13:59
Jacob Sorber
Рет қаралды 40 М.
The What, How, and Why of Void Pointers in C and C++?
13:12
Jacob Sorber
Рет қаралды 51 М.
What is virtual memory? - Gary explains
11:28
Android Authority
Рет қаралды 296 М.
How to Check Your Pointers at Runtime
14:12
Jacob Sorber
Рет қаралды 30 М.
i wrote my own memory allocator in C to prove a point
5:23
Low Level Learning
Рет қаралды 350 М.
Virtual Memory: 3 What is Virtual Memory?
8:47
David Black-Schaffer
Рет қаралды 672 М.
Stack vs Heap Memory - Simple Explanation
5:28
Alex Hyett
Рет қаралды 197 М.
How Memory Usage Slows Down Your Programs
9:17
Jacob Sorber
Рет қаралды 19 М.
I CAN’T BELIEVE I LOST 😱
00:46
Topper Guild
Рет қаралды 49 МЛН