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

Поделиться
HTML-код
  • Опубликовано: 7 ноя 2024

Комментарии • 187

  • @DenisFalqueto
    @DenisFalqueto 3 года назад +125

    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)

    • @MrEnsiferum77
      @MrEnsiferum77 2 года назад +4

      Maybe the ownership is different, but everything else is school thing explained here.

    • @dreastonbikrain1896
      @dreastonbikrain1896 Год назад +1

      @@MrEnsiferum77 could you point me to a program or a book where theese things are taught to people?

  • @snwbrdr36
    @snwbrdr36 3 года назад +71

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

  • @Ma1ne2
    @Ma1ne2 2 года назад +23

    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!

  • @暴打麻薯
    @暴打麻薯 2 месяца назад +2

    这个视频实在讲的太好了,解答了我好多关于Rust的疑惑以及Java中的一些疑惑!!追过来点赞

  • @MasterSpencer2483
    @MasterSpencer2483 9 месяцев назад +1

    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

  • @aqua3418
    @aqua3418 2 года назад +44

    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)]`

  • @sreekanthpr
    @sreekanthpr  3 года назад +69

    *UPDATE: This video is re-uploaded with a better audio here* ruclips.net/video/7_o-YRxf_cc/видео.html
    Corrections:
    * 6:10, it should be 2^64 - 1 (without parenthesis)
    * Trait is dynamically sized. Trait object has known size.

    • @dersebastianbauer
      @dersebastianbauer 3 года назад +4

      28:22 this isn't precise. Gargabe collection (as in JS, Go or Java) does not keep track of refernces. In its cleanup run GC just checks wether there is a reference to this memory or not and after it is finished it forgets about it. Your description fits more to automatic reference counting used by Objective-C and Swift.

    • @shumudu5377
      @shumudu5377 2 года назад

      by which software are the pictures drawn?

    • @sreekanthpr
      @sreekanthpr  2 года назад +1

      @@shumudu5377 For this video, I used Powerpoint. For all other videos in this channel, I use manim library (Python).

    • @parry84
      @parry84 2 года назад +3

      at 28:10, I suppose the indices should be 0, 1, 2 instead of 0, 2, 3.
      btw great video, thanks you ❤

    • @noop9770
      @noop9770 2 года назад +2

      * trait objects are dynamically sized types, meaning that their size is known at runtime.
      Pointer types to trait objects are sized at compile-time but have twice the size of pointers to sized types.
      Correct me if i got something wrong

  • @adammontgomery7980
    @adammontgomery7980 2 года назад +2

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

  • @Gabriel_Bento
    @Gabriel_Bento 2 дня назад

    I'm really impressed, what a great content avaliable for FREE! Please keep up uploading videos.

  • @sanket1729
    @sanket1729 2 года назад +4

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

  • @procyonq
    @procyonq 2 года назад +2

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

  • @isaaccespedes4817
    @isaaccespedes4817 Год назад

    Thank you Sreekanth. Coming from a C background, this really helped me understand what Rust is about.

  • @slava_in3757
    @slava_in3757 Год назад +2

    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!

  • @bugsenthil
    @bugsenthil 10 месяцев назад

    The best video on vtable , Smart pointers, trait object..Awesome job. Thanks

  • @xyve6129
    @xyve6129 Год назад +2

    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.

  • @김화겸-y6e
    @김화겸-y6e 2 года назад +1

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

  • @rajesh_404
    @rajesh_404 2 года назад +1

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

  • @GeorgeFosberry
    @GeorgeFosberry 2 года назад +1

    A nice overview and/or refresher.

  • @ikhlasulkamal5245
    @ikhlasulkamal5245 Год назад

    This is very clear and great explanation on rust memory management. thanks for the explanations

  • @chudchadanstud
    @chudchadanstud Год назад

    Thank a lot, this makes learning Rust a lot easier. The less magic the better.

  • @mohitpawar8582
    @mohitpawar8582 2 года назад +1

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

  • @jonathanmoore5619
    @jonathanmoore5619 3 года назад +2

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

  • @yapayzeka
    @yapayzeka 2 года назад

    this is the best memory video ever made. I downloaded it because of fear to lose it if youtube servers shut down or volcano, earthquake, meteor or something... lifesaving enum memory tip @23:55

  • @jeffvandyke1239
    @jeffvandyke1239 2 года назад +2

    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.

  • @askhatarslanov6327
    @askhatarslanov6327 2 года назад +1

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

  • @Onkoe
    @Onkoe Год назад +1

    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! :)

  • @johndavies729
    @johndavies729 2 месяца назад +1

    Hey! Great video! I’d love to do a voiceover for this to make it easier to listen to.

  • @360nickx
    @360nickx 3 года назад +12

    Thanks for this. It is brilliant!

  • @rajesh_404
    @rajesh_404 2 года назад +1

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

  • @accumulator4825
    @accumulator4825 5 месяцев назад

    Really appreciate this video, thank you

  • @malharvora1281
    @malharvora1281 3 года назад +1

    Easy to understand video for complex concepts. Thanks for sharing.

    • @malharvora1281
      @malharvora1281 3 года назад

      It would be awesome if you put more Rust-related videos with the same level of explanation. IMHO there are a lot of videos of Rust internals available on RUclips but only a few like this, are actually understandable by novice Rustaceans.

  • @leonlee9518
    @leonlee9518 Год назад

    This video help me understand rust memory a lot , thanks ~

  • @norberthajagos
    @norberthajagos Год назад

    Extremly well delivered information with not a single wasted second. Very good work!

  • @scorpo999
    @scorpo999 2 года назад

    This is worth more than some of computer arch classes at university.👍

  • @sokolorlov996
    @sokolorlov996 Год назад

    Visualization helps a lot, thanks!

  • @HansFlamme
    @HansFlamme 2 года назад

    I recently started with rust and holy shit i can'ttell how helpful this was

  • @JoaoBosco89
    @JoaoBosco89 Год назад

    Your video helped me a lot. Thank you.

  • @nekokuro9910
    @nekokuro9910 3 года назад +2

    This video is so good and easy to understand

  • @morgomi
    @morgomi Год назад

    the best introduction has ever seen.

  • @Policritics
    @Policritics 2 года назад

    This is the best explain to Rust

  • @jokerdevilarm
    @jokerdevilarm 2 года назад +1

    The best video!!! Thnx

  • @marcoantonio7648
    @marcoantonio7648 Год назад

    This video is gold. Thanks for the hard work!

  • @brethagen7776
    @brethagen7776 11 месяцев назад

    This video is beautiful

  • @JayDee-b5u
    @JayDee-b5u 8 месяцев назад

    Wonderful. So thorough.

  • @juanma3333
    @juanma3333 3 года назад +2

    This is awesome! I didn't know that I needed this that badly! Thanks for sharing this great work!

  • @sanjusk4287
    @sanjusk4287 2 года назад +1

    Such wisdom, oh great one.

  • @ClearerThanMud
    @ClearerThanMud 3 года назад +3

    Nice work! Hope to see more Rust videos from you.

  • @Leonardo-ms6re
    @Leonardo-ms6re 3 года назад +2

    This is gold! Congrats :)

  • @ingmarfalk3306
    @ingmarfalk3306 11 месяцев назад

    Bro this was so cool, loved the video even tho it was with an AI voice, usually dont like those but the content was NOICE

  • @nurmohammed9642
    @nurmohammed9642 2 года назад +2

    We rustacean loved it! you should create more videos about rust, like this one!

  • @dk5146
    @dk5146 Год назад

    need more videos like this

  • @tuanlam999
    @tuanlam999 2 года назад

    Great explanation. Love to see more such deep dive video about Rust.

  • @vmscode
    @vmscode 2 года назад +1

    Amazing video! Would be awesome if you made more videos like this for Rust

  • @InMemoryOfNeo
    @InMemoryOfNeo Год назад

    awesome explanation 👏👏👏👏👏

  • @xl0xl0xl0
    @xl0xl0xl0 2 года назад

    This makes so much more sense! Could you please cover RefCell?

  • @arash2229
    @arash2229 2 года назад

    bruh I loved this video. thanks for your great content.

  • @xenocampanoli815
    @xenocampanoli815 Год назад

    The mention of "malloc" made me think of the assertions around self-compiled language aspects, something I first remember hearing about with Pascal, then C. I presume then this does not include the libc and some other libraries, or perhaps just not always. I guess if it is a clang compilation, by implication, it's not self-compiled, so perhaps the assertion is it is self-compiled in some environments, or that some copies are self-compiled, or that the core of the compiler is self-compiled, but not all the libraries it uses.

  • @mokorra
    @mokorra Год назад

    very informative! thank you

  • @maximus1172
    @maximus1172 Год назад

    I cannot thank you enough 🙏

  • @richmondgnu
    @richmondgnu 2 года назад

    thank you for sharing knowledge. appreciate the effort.

  • @abteyeb7969
    @abteyeb7969 2 года назад

    very good and clear

  • @akatsukinoh7660
    @akatsukinoh7660 2 года назад

    This is exactly i want. Thank you!

  • @MiniKodjo
    @MiniKodjo Год назад +2

    An unsecure low shy stuttering voice sounds always better than any AI voice.... Remember this for your next videos

  • @ozanmuyes
    @ozanmuyes 2 года назад

    This is golden, thanks!

  • @young_kido2293
    @young_kido2293 2 года назад

    Thank you man for sharing this stuff

  • @michaelmueller9635
    @michaelmueller9635 Год назад

    This is high quality stuff!

  • @reneribaud8912
    @reneribaud8912 8 месяцев назад

    Amazing video thanks.

  • @dixztube
    @dixztube 4 месяца назад

    Wow this is awesome

  • @tadeohepperle
    @tadeohepperle Год назад

    This is so useful! Thanks

  • @lavienrozy1867
    @lavienrozy1867 2 года назад

    O Captain! My Captain! Are you going to publish a book? I think we need more lectures for memory dynamics.

  • @Nre11
    @Nre11 3 года назад

    Wow, honestly incredible

  • @Paxsali
    @Paxsali 2 года назад +2

    is the first word in each spoken sentence omitted?

  • @nav-on
    @nav-on 2 года назад

    love it help me a lot i hope you do cargo next!

  • @КириллПальцев-ю1о
    @КириллПальцев-ю1о 3 года назад

    Dude, amazing work! Just amazing

  • @tanuvishu
    @tanuvishu 2 года назад

    Awesome explaination

  • @mustafaerdemkoc2529
    @mustafaerdemkoc2529 2 года назад

    Thank you! this was very helpful.

  • @devlogschannel
    @devlogschannel 23 дня назад

    Thank you so much

  • @ancientITguy
    @ancientITguy 2 года назад

    Great explanation! Thanks

  • @robertandrzejczyk
    @robertandrzejczyk 2 года назад

    It is a cool video. Not only for Rustaceans.

  • @snk-js
    @snk-js 2 года назад

    this is the best video I have ever watched on youtube

  • @aaryanpashine6633
    @aaryanpashine6633 Год назад

    holy shit this was amazing

  • @luiscarlosjayk
    @luiscarlosjayk 7 месяцев назад

    Why the Array(Vec) variant of the Data enum is stored in stack if in the Vector section of the video it was explained that Vectors were stored in the heap so they can grow.

    • @sreekanthpr
      @sreekanthpr  7 месяцев назад +1

      The three elements that constitute the Vec header (pointer to data, length and capacity) are stored on the stack. The Vec elements will be stored in the heap.

    • @luiscarlosjayk
      @luiscarlosjayk 7 месяцев назад

      @@sreekanthpr thank you!!!!, I watched that section again and now I understood it better. I loved this visual explanation, everyone else does it with charts and words, but having it visually explained like you did totally improves and easies the understanding of these abstractions. Again, thank you!

  • @georgereasonproductions
    @georgereasonproductions 3 года назад +1

    love to learn thanks for sharing

  • @RivoMPutra
    @RivoMPutra 2 года назад

    just beca a subscriber keep up the good work Sir.

  • @MrSasukeUchihaEMS
    @MrSasukeUchihaEMS 2 года назад

    good stuff, thank you very much

  • @zeev549
    @zeev549 2 года назад

    Thanks!
    What tts do you use?

    • @sreekanthpr
      @sreekanthpr  2 года назад +1

      Microsoft one note >> View >> Immersive reader

  • @RAHUDAS
    @RAHUDAS 2 года назад

    great work, very helpful for me

  • @soapbubblesx
    @soapbubblesx 3 года назад

    Enlightening! Thank you!

  • @dionysis_
    @dionysis_ 2 года назад

    That was very useful 👍

  • @ehkhe2650
    @ehkhe2650 2 года назад +1

    18:50 Couldn't the compiler get the size for a slice from it's initializer? It should know the size is 2 if I say 0..2. It's something like `constexpr` in C++.

  • @talalkalai8748
    @talalkalai8748 Год назад

    can u upload same kind of video for cpp r/l values / move semantics?

  • @parthivmangukiya5953
    @parthivmangukiya5953 2 года назад

    Thanks!!! Your video is too good

  • @drsensor
    @drsensor 2 года назад

    Could you put it in the video description of what NTTS model/engine you are using to dub this amazing video?

    • @sreekanthpr
      @sreekanthpr  2 года назад

      I use Microsoft onenote/word >> View >> Immersive Reader

  • @b5eu6b87
    @b5eu6b87 3 года назад

    extremely well done video!

  • @JasonFritcher
    @JasonFritcher 3 года назад +4

    Great video, thanks!
    At 6:10, there is an error for the address range. The caption reads 2^(64-1), which is incorrect, as it implies 2^63 because of the parenthesis. The parens either needs to be removed, or put around the exponent to be correct.

    • @sreekanthpr
      @sreekanthpr  3 года назад +1

      Thank you. Happened during the final subtitle edits. It was written in words for generating the sound in the original text.

  • @alexloktionoff6833
    @alexloktionoff6833 Год назад

    Is it possible to make borrow-checker to take care of individual structure fields? I mean I want to pass the whole structure mutable reference in/out for functions, but to make the borrow-checker to care about what fields has been modified. Is it?

  • @ehsankhorasani_
    @ehsankhorasani_ Год назад

    why does the kernel add some paddings in memory when storing enums. I know it's to have the same size for every enum type. but why do we have to have the same size?

  • @iamwhoiam798
    @iamwhoiam798 Год назад

    Appreciate if you could explain the way Rust return structs created in stack. Does the entire struct members get copied from lower stack frame to the upper ( caller ) ?

    • @sreekanthpr
      @sreekanthpr  Год назад

      Yes, Rust will copy the whatever is stored in the stack for that struct. If there's something in the heap (eg. if one field is a String), that is not copied. The heap part of a data structure is copied only if you explicitly call the `.clone()` method.

  • @azertycraftgaming
    @azertycraftgaming Год назад

    I was looking forward to this video wehn seeing the title and then bam! Text to speech 😢

  • @happilyconfuseddog8951
    @happilyconfuseddog8951 Год назад

    Great ty ty