Visualizing memory layout of Rust's data types [See description/first comment]

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 Segments in a binary
3:14 Stack & Heap
5:46 CPU Word size
7:08 Working of stack memory
10:25 working of Heap memory
14:00 Integer data types
14:30 char
15:15 size_of & align_of
15:51 Reference
16:58 Array
17:21 Vector
18:19 Slice of T
19:54 String, str, &str
21:17 Struct
22:14 Enum
24:14 Box pointer
24:51 Optimizations on Option
26:34 Copy Vs Move
29:21 Rc pointer
30:45 Send vs Sync traits
31:00 Why RC is neither Send nor Sync
31:24 Arc
32:19 Trait object
34:20 Function pointer
34:37 Closures

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

This solved lots of misunderstandings I had about Rust. It should be placed right in the documentation of the language (at least a link, so one could find it easily and early on the rust book)

DenisFalqueto
Автор

This was extremely enlightening in visualizing rust's memory model. Thank you for taking the time to create this!

snwbrdr
Автор

This is not just a great video for Rust developers, but a great introduction for all developers into the process' memory layout and workings of the operating system!

Mane
Автор

Corrections:
* 6:10, it should be 2^64 - 1 (without parenthesis)
* Trait is dynamically sized. Trait object has known size.

sreekanthpr
Автор

Just remember about the memory layout of things like structs. You CANNOT rely on the memory layout or ordering of fields to be a certain way, as it's not defined how it will end up. If you need to rely on this, you need to use things like `#[repr(C)]`.

In fact, not even the tuple struct's memory layout is guaranteed. To guarantee it, you would need to use `#[repr(transparent)]`

aqua
Автор

I was looking for info on dynamically sized types, but I found so much more in the video. One of the clearest explanations for such confusing concepts in Rust. Great video!

slava_in
Автор

Definitely the best Rust video on Youtube. I will keep this video and watch again and again! 감사합니다🙏

procyonq
Автор

Wow, I really love this. Nice refresher of multiple topics even for someone who is intermediate-advanced rust user.

sanket
Автор

This video will remain as the best go-to video for new rustaceans! Excellent work Sreekanth!!!

rajesh_
Автор

I was confused about box, rc, and arc until now. Thanks!

adammontgomery
Автор

Incredible explanation, it makes it so much easier to understand compiler errors when you have this video and memory mapping in mind. Thanks !

joelimbergamo
Автор

Great video. I wanted to check out Rust for use in userspace applications, however the types seemed too high level and convoluted to me, since I primarily program in C. This video helped visualize the types and allows me to think of them in a more familiar C like way and visualize them in memory. I feel like every languages needs videos like this, as it makes mechanisms within the language more explicit and easy to understand in simpler terms.

xyve
Автор

finally I've understood strings in rust. thank you a lot!

askhatarslanov
Автор

Jesus Christ. This is so awesome explanation. Thanks to you I can be now understanding how stack and heap grows up

rssgtzk
Автор

Hats off for making everything clear🙌 You're extremely talented. You're able to explain things logically by providing reasons. Thanks❤️

rajesh_
Автор

Beautiful, I'd consider the topics covered here to be required knowledge, and the video is a nice way to present things that can be difficult to visualize.

jeffvandyke
Автор

Rust is the way forward and this is a great piece of work. Thanks.

jonathanmoore
Автор

Great lecture, but in the future, consider asking a friend to narrate! I know a lot of people don’t like posting themselves online, but many people would probably be happy to help out! :)

Onkoe
Автор

Very useful and nice depiction of memory layout of each data type. It should be placed right inside the documentation

mohitpawar
Автор

Genuinely, thank you SO much for this video. I was banging my head against a wall trying to PRECISELY understand fat pointers, why str is a primitive type, and other low-level questions

MasterSpencer