Visualizing memory layout of Rust's data types

  Рет қаралды 8,103

Sreekanth

Sreekanth

Күн бұрын

Covers how a binary is executed, what segments are mapped to memory, the purpose/working of stack and heap memory, and how values of Rust's data types are laid out in memory. The data types that we cover here are integers, char, Vector, slice, String, string slice, structs, enums, smart pointers like Box, Rc, Arc, Trait object and Fn traits like FnOnce, FnMut and Fn.
We also cover the difference between String and str types, Vector and slice types. Topics like fat pointers, optimizations done by the Rust compiler when you wrap a reference inside an Option are also covered.
0:00 Intro
0:41 Segments in a binary
3:09 Stack & Heap
5:35 CPU Word size
6:57 Working of stack memory
10:16 working of Heap memory
13:58 Integer data types
14:28 char
15:13 size_of & align_of
15:51 Reference
16:58 Array
17:22 Vector
18:19 Slice of T
19:54 String, str, &str
21:09 Struct
22:04 Enum
23:48 Box pointer
24:43 Optimizations on Option
26:27 Copy Vs Move
29:21 Rc pointer
30:49 Send vs Sync traits
31:05 Why RC is neither Send nor Sync
31:24 Arc
32:25 Trait object
34:27 Function pointer
34:44 Closures - Fn, FnOnce, FnMut
Life of an async fn: • RustFest Barcelona - T...
stack & heap / virtual address space:
lwn.net/Articles/738975/
docs.microsoft.com/en-us/wind...
Book: Programming Rust by Jason Orendorff, Jim Blandy, and Leonora F.S. Tindall

Пікірлер: 34
@JaLikon65
@JaLikon65 4 ай бұрын
I genuinely think this video should be included in The Rust Book. It is an absolutely incredible resource. Thank you Sreekanth!!! This is amazing.
@laplacedoge
@laplacedoge Ай бұрын
This video should be seen by more people!
@returncode0000
@returncode0000 19 күн бұрын
This is the best rust explanation video in the world. I would give anything if there also is an in-depth look at the concepts of functional programming in rust explained like in this video because those concepts are crucial to understand rust and I'm still struggling to understand them.
@kaansouth8789
@kaansouth8789 18 күн бұрын
This was INSANELY helpful. Thank you so much! 🙏🙏🙏
@turun_ambartanen
@turun_ambartanen 7 ай бұрын
Thank you for uploading with better audio. I could not stand the voice of the other version, but this one is alright to listen to. Great video!
@0runny
@0runny 7 ай бұрын
This is an excellent video! It really helps you understand the WHY's of different memory management techniques in Rust. Many Rust videos explain how to do things, but very few explain why to do things. This video is a must watch if you really want to understand Rust under the covers. Well done!
@aimericsorindev253
@aimericsorindev253 3 ай бұрын
Thank you for your work, this is I think the best video I've seen about this subject and the first time I clearly understand the memory management in Rust. Clearly a video all people learning rust should watch. Really nice explanations on why things work like this and not just how. If you could do a video about async rust / Tokio that would be awesome !
@psychechip
@psychechip 3 ай бұрын
Thank you for your work. This video clarified many questions I had about memory alignment and helped me to understand how Rust is able to perform some optimizations, such as using a single usize for storing an Optional RC and Box. Keep up the good work!
@NimaqAlizadeh
@NimaqAlizadeh 11 күн бұрын
very very helped me. thanks a lot🎉🎉
@clintondannolfo714
@clintondannolfo714 Ай бұрын
Incredible video, thank you very much!!
@zubiarfan
@zubiarfan 6 ай бұрын
Thank you so much for reuploading
@juliansteden2980
@juliansteden2980 8 ай бұрын
Wow, thanks a lot! This is very well done! Great visualizations and explanations 😊
@Gruby7C1h
@Gruby7C1h 6 ай бұрын
Thanks for updating the audio!
@longpos222
@longpos222 2 ай бұрын
Thank you so much bro.
@ItsMorze
@ItsMorze 6 ай бұрын
very good video! first time I really understood how stuff works behind the scenes! especially with rust enums - I didn't know it's like a union maybe do a follow up video on interior mutability, that'll be really interesting!
@michah3956
@michah3956 8 ай бұрын
Rust 💟
@korigamik
@korigamik 6 ай бұрын
This is cool. Can you tell us what you used for animating these graphics and the text? Also what audio generator is used here?
@sreekanthpr
@sreekanthpr 6 ай бұрын
- For this one, I used powerpoint to generate the video. For all other videos in this channel, I use github.com/ManimCommunity/manim. - Audio is generated with TTS service in Azure. Combined both with Davinci Resolve. - Subtitles with timings can be generated with github.com/m1guelpf/auto-subtitle (minor corrections will be needed).
@yapayzeka
@yapayzeka 2 ай бұрын
autoread got just promoted to the next level lol
@dagoberttrump9290
@dagoberttrump9290 29 күн бұрын
i don't understand why can't slices be allocated on the stack? in c++ they do and i think it's the same in rust also are sou sure that enums store index for each element? in c++ variants only the index of the alternative is stored which is enough to denote the type of the underlying union.
@rsalmei
@rsalmei 22 күн бұрын
Actually, at 19:10 you've made an incorrect amend. Trait objects are in fact DSTs, that was correct. Remember you can't create an array or slice of trait objects - [dyn Trait] - or receive one as a parameter - fn func(x: dyn Trait) - or use `self` in a Trait method, because each Trait implementation will have a different size. What do have known sizes are owned trait objects - e.g. Box and other smart fat pointers - and references to trait objects - &dyn Trait.
@prashlovessamosa
@prashlovessamosa 5 ай бұрын
Your are goat.
@muizzsiddique
@muizzsiddique 3 ай бұрын
Better yet, do you have a written version of this with embedded images of the diagrams in this video? -This is quite informative, but the generated voice's intonation is making it difficult to pay attention or process the information given.-
@sreekanthpr
@sreekanthpr 3 ай бұрын
Most of this is covered in the book "Programming Rust"
@muizzsiddique
@muizzsiddique 3 ай бұрын
@@sreekanthpr Thank you!
@user-el4ht5xi9i
@user-el4ht5xi9i 7 ай бұрын
35:10 probably not true, because the same example not compiles, if use something meaningful like println, not drop upd. i mistaken, seems like thats because of using println
@matthewdillingham4941
@matthewdillingham4941 8 ай бұрын
Reupload with different automated voice?
@sreekanthpr
@sreekanthpr 8 ай бұрын
Yea. I feel this audio is better compared to the one in the first video.
@MrHirenP
@MrHirenP 8 ай бұрын
What’s the reason you don’t narrate it yourself?
@emionyt
@emionyt 8 ай бұрын
@@sreekanthpr I agree, this voice is way less noisy and more natural
@chriswilliamson4693
@chriswilliamson4693 8 ай бұрын
@@MrHirenP I would also like to know
@ChainOfCommand12
@ChainOfCommand12 7 ай бұрын
@@MrHirenP maybe he has health issues, maybe he's insecure, maybe his english pronunciation isn't good. doesn't matter, he's posting excellent content
@ajithmaster1234
@ajithmaster1234 8 ай бұрын
Very useful, could you do a video on zig allocators?
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 146 М.
But, what is Virtual Memory?
20:11
Tech With Nikola
Рет қаралды 196 М.
UFC 302 : Махачев VS Порье
02:54
Setanta Sports UFC
Рет қаралды 1,3 МЛН
Чай будешь? #чайбудешь
00:14
ПАРОДИИ НА ИЗВЕСТНЫЕ ТРЕКИ
Рет қаралды 2 МЛН
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,8 МЛН
How variables works in Python | Explained with Animations
18:39
Sreekanth
Рет қаралды 4,9 М.
Understanding Static, Stack, and Heap Memory Regions (Examples in C)
33:29
The Ultimate Tier Programming Tier List | Prime Reacts
26:57
ThePrimeTime
Рет қаралды 305 М.
Why does this Rust program leak memory?
35:24
fasterthanlime
Рет қаралды 56 М.
WHY IS THE HEAP SO SLOW?
17:53
Core Dumped
Рет қаралды 193 М.
Constructors Are Broken
18:16
Logan Smith
Рет қаралды 99 М.
Where are types allocated in .NET and why people get it so wrong
14:35
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 125 М.
Stack vs Heap Memory - Simple Explanation
5:28
Alex Hyett
Рет қаралды 189 М.
UFC 302 : Махачев VS Порье
02:54
Setanta Sports UFC
Рет қаралды 1,3 МЛН