Visualizing memory layout of Rust's data types

preview_player
Показать описание
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

stack & heap / virtual address space:
Book: Programming Rust by Jason Orendorff, Jim Blandy, and Leonora F.S. Tindall
Рекомендации по теме
Комментарии
Автор

I genuinely think this video should be included in The Rust Book. It is an absolutely incredible resource. Thank you Sreekanth!!! This is amazing.

JaLikon
Автор

This video should be part of "The Rust Book". This really explains why rust has so many data types. We need more rust videos. Thank You Sreekanth 👏👏

PrinceKumar-uky
Автор

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!

runny
Автор

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!

turun_ambartanen
Автор

Amazing content, please do more rust themed deep dives

HereIsZane
Автор

i love this video so much

do you have sources for this material?

jkjoker
Автор

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 !

aimericsorindev
Автор

Incredible video, thank you very much!!

clintondannolfo
Автор

This video should be seen by more people!

laplacedoge
Автор

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<dyn Trait> and other smart fat pointers - and references to trait objects - &dyn Trait.

rsalmei
Автор

around 11:00 isn't it a move instead of copy?

focker
Автор

Is this presentation available anywhere?

sandrokavlashvili
Автор

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!

psychechip
Автор

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.

returncode
Автор

This was INSANELY helpful. Thank you so much! 🙏🙏🙏

kaansouth
Автор

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!

ItsMorze
Автор

Excellent video. I just wish animation of the stack to show chunks of memory allocated like a stack (one on top of the other) and freed the same way. I find it more intuitive.

OzWannabe
Автор

This is cool. Can you tell us what you used for animating these graphics and the text? Also what audio generator is used here?

korigamik
Автор

Reupload with different automated voice?

matthewdillingham
Автор

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.-

muizzsiddique