Rust Tutorial #9 - Memory Management, Heap & Stack

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

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

  • @unstablecoding
    @unstablecoding 7 месяцев назад +21

    Tim please continue this series, PLEASE?!!

  • @jontassin8385
    @jontassin8385 2 года назад +240

    Will this series be continued? I'd love to see more of these, great videos!

    • @akash-kumar737
      @akash-kumar737 Год назад +11

      Saidly series look dead too me😢

    • @kazuhah1743
      @kazuhah1743 Год назад +6

      @@akash-kumar737 seriously, it's for the better

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

      @@brinblasco9037 for those who writes in similar low level languages, there are plenty of dead giveaways...i agree it's better for this channel to focus with Python. There are other channels who have mastered Rust and therefore much less misleading concepts (hint: read other comments here who have some experience with Rust..)

    • @ttz8488
      @ttz8488 6 месяцев назад

      @@kazuhah1743 Why?

  • @petermuwanguzi3787
    @petermuwanguzi3787 2 года назад +189

    Still waiting on Rust Tutorial #10 - Ownership

    • @ClasherSPOT
      @ClasherSPOT Год назад +5

      Same here

    • @_sjoe
      @_sjoe Год назад +30

      Bro really left us hanging at the toughest part 😂

    • @Leo_Aqua
      @Leo_Aqua 11 месяцев назад +7

      this video released 1 year ago 🥲

    • @aflous
      @aflous 10 месяцев назад +11

      2024 and still waiting..

    • @flachmann161
      @flachmann161 10 месяцев назад +2

      Just read the Rust Book

  • @clot27
    @clot27 Год назад +41

    Please continue the series Tim, I love rust and it is a huge language. I hope you cover mos of the things in it

  • @donythomas7
    @donythomas7 Год назад +19

    10:50 - string literal like "true" is actually stored in the read-only data segment of the executable. In the stack, value of 'a' is a fat pointer (pointer + length) to this read-only data segment.

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

      This needs more attention / likes

  • @MarioPL989
    @MarioPL989 2 года назад +15

    So, yeah, I'm addicted to this series now. Need more.

  • @thecodingturkey3157
    @thecodingturkey3157 2 года назад +26

    Hey Tim, I can't say my thanks enough for you. You are the person that inspires me to start my coding channel. Because of your channel, I was able to jumpstart my coding experience and learn more on my own. If anyone is reading this comment and is starting out on their coding journey, I highly recommend Tim and Sentdex for their amazing projects. It's because of people like Tim that motivates me to learn other languages besides Java, which is being taught in my school (and very poorly taught). Anyway, Tim, keep up the amazing work and I can't wait to see how far you'll go with this Rust tutorial! ❤️

  • @williamiiifarquhar4345
    @williamiiifarquhar4345 Год назад +15

    Thank you Tim for these videos!
    This was a great introduction to the rust syntax and I hope that you continue the series.

  • @alfredomenezes8814
    @alfredomenezes8814 2 года назад +12

    This rust series is amazing, thank you very much, can't wait for the next episodes! I've just turned a member of the channel to support you with that ❤️

  • @davidsimek1197
    @davidsimek1197 2 года назад +7

    Thanks, I am beginner to medium Java developer and i wanted to learn something more low level. I am happy i found you. I cant hold and I am learning other things because I cant wait for another video, but these fundamentals are super interesting and i wouldnt probably learn them in this stage by my own study. Again, thank you for this.

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

    Tim of you read this comment, please continue this series at some point. It's the most comprehensive rust tutorial in YT.

  • @mechwarrior83
    @mechwarrior83 Год назад +7

    Amazing series! I love that it was aimed at the intermediate programmer. I hope you will continue this!

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

    Hey Tim,
    Thanks for these videos.
    May you kindly continue the series.

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

    Would love to see this series continued. Thanks for the great introduction to Rust

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

    Tim, continue this series, you explain Ⓡust so well!

  • @uarweak
    @uarweak Год назад +3

    Please continue this series. Your videos are a 10/10

  • @Masterix.
    @Masterix. 2 года назад +8

    Continue with the tutorials, please!

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

    Pls continue this seires, you are a very good teacher!

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

    Another vote for the series to continue. You have a very clear presentation.

  • @CallousCoder
    @CallousCoder 2 года назад +7

    Also the heap isn’t that much slower after you have obtained the pointer to the starting memory page.
    You still need to dereference an address but the same goes for the stack pointer that you need to count back from the current point to the right variable that’s actually an extra indirect addressing function whereas the heap it’s optimized so that the pointer is already in a register “load effect address” and the data is also obtained using indirect addressing with offset. So in use it’s pretty similar in speed on some systems even identical because they don’t have shorter opcodes for best by addresses.
    But yeah, the allocation and freeing is where the performance pain is. And in some cases also the fact that the data is too large or randomly accessed to fit in level 2 cache.

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

    Tim please return with more tutorials. I prefer your videos over the official rust manual and other tutorials.

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

    Man, I hope this series continues 🙏

  • @MrSmartTutorials
    @MrSmartTutorials 4 месяца назад +1

    Legend has it that the next video is still on its way!

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

    I hope you continue this series. I like most of your videos, and a few years ago, your 6-hour, no-ads Python beginners course rekindled my interest in writing software after around 30 years away from it. This set, as interesting and helpful as it definitely was, felt like it just abruptly ended. Just like . . . we're done! Thanks for the lessons you posted, and I hope you decide to post more.

  • @CallousCoder
    @CallousCoder 2 года назад +7

    You forgot that before a and b there’s the return pointer from where example() was called. And ofcourse there’d no name associated in the stack, the arguments are derived from their size.
    And the values aren’t removed from the stack, the stack frame pointer is subtracted. The stack is never cleared that’s why it’s so fast, it’s just a stack pointer register that’s subtracted from.

    • @peircedan
      @peircedan Год назад +4

      Thank you for that. I don't know much about rust but have used C for a long time. I expect in a compiled language variable names are not retained in the compiled code. For C the compiler maintains a name table that associates names with addresses and/or address offsets. The compiled code only uses the addresses and offsets and knows nothing of the variable names in the source code. From this perspective I see the explanations given in this video as overly simplistic and misleading. I'm going to unsubscribe and look for a more realistic series.

  • @knirvan
    @knirvan 6 месяцев назад

    Please continue Tim. Your rust videos helping me a lot...

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

    This is a very insightful video. Hope you continue this series.

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

    This series needs to be continued Tim. Please

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

    Thanks Tim, It was very good. Please make more videos about Rust. Good luck 🙏

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

    Would love to see this video series continued!

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

    This video series is awesome, thank you so much for making these videos!

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

    I'm glad that I've stumbled across this series, it was simple and straightforward. I didn't think that Rust can be learnt this easily.
    Deserves a subscribe!

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

    The series helped a lot!!! Waiting for next advanced series on rust Tim!!!!

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

    This is a helpful series. Like the others have mentioned, I hope the series continues to #10 and beyond.

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

    The programming language FORTH is a great exercise/example when talking about the stack.

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

    We need part 10!

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

    Please continue the series!!! 🙏🏼

  • @joshuao4928
    @joshuao4928 2 года назад +6

    Tim, have you given up on this playlist? I know you've got a lot of irons in the fire, but you did the first nine of these in one month and now it's been over two months since the last.

  • @JackTheGroenendael
    @JackTheGroenendael 2 года назад +5

    From my old days with c, everything on the stack is referenced via a stack pointer. So when data goes out of scope, they aren't really deleted.. the stack pointer is just decremented.

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

      Also, the stack are actually multiple stacks, one for each process. This is one of the reasons you cannot have data there that can dynamically grow. It might overwrite other stacks.

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

    Fantastic explanation, looking forward to the next video.

  • @md.shazidalhasan6726
    @md.shazidalhasan6726 2 года назад +1

    Congratulations on 1 millions

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

    Gotta love the difference between strings and Strings

  • @Harshit-ju2iz
    @Harshit-ju2iz 10 месяцев назад

    Continue the series please!

  • @embeddedbastler6406
    @embeddedbastler6406 2 года назад +7

    15:50 The string literal isn't stored on the stack either. It will be placed into the read-only section of the binary.
    We only get a &str reference to the string literal. Generally it is not possible to store str on the stack as str is not sized. We always need some kind of pointer such as a reference &, a Box, Rc, Arc, and so on.

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

    Bro is teaching us about memory management before for and while loops

  • @felixc.programs8209
    @felixc.programs8209 2 года назад

    Good video as always! Your content is one of the main reasons I started my (still small) Tech RUclips channel myself. Thanks and have a good day!

  • @driftwood-f4p
    @driftwood-f4p Год назад

    Thank you very much! your explain is very understandable.

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

    Nice!!! Very nice thanks for explaining memory, this is often brushed by in many tutorials.

  • @RobertLugg
    @RobertLugg 9 месяцев назад

    Nice work on these!

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

    Okay, that's a bit weird. Stacks normally grow up, not down. It's called a stack because it stacks up from higher address (aka bottom of memory) to lower addresses.

  • @jahelation8658
    @jahelation8658 2 месяца назад

    Thanks - like your explanations. Pity you did not continue the series.

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

    Thanks for your Rust videos! Will you break the suspense and continue?

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

    He will probably ignore these comments because he don't care about what we say as long as we are watching his videos. That's fine for him.

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

    I'm guessing that you're done with the Rust series, despite mentions of future videos? The playlist ends at #9

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

    No rust #10?
    Thanks for the series anyway! It's so nice to watch your video

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

    Why didn't you continue this series? Your explanation is very intuitive.

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

    Great video, the explanation is very clear, thanks so much.

  • @EntangledFrequency
    @EntangledFrequency 11 месяцев назад +1

    My lust for Rust is a must as the luster of Rust is a muster for bust.

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

    This is very helpful, but I REALLY wish you would have started with the stack address as 43210 and put everything on the bottom first then stack it as they are added like you were trying to explain but for some reason you illustrated it upside down.

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

    Tim! We're nearing 1 Million subs bro! 🥳🎉🎉

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

    Please countinues this series,

  • @flames1087
    @flames1087 Месяц назад

    Waiting for continuation 🥺

  • @shivam-codes
    @shivam-codes 9 месяцев назад +1

    some people say bro is still learning ownership concepts ...

  • @robertdreyfus5436
    @robertdreyfus5436 3 месяца назад

    At 10:40 when example() function is called, a return address will be pushed on the stack, but the string "true" will not. Why not use a debugger and step through the program instructions one by one and watch what happens on the stack, heap, registers etc? That would be a super video to make!

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

    Are you going to continue this? I'm invested now! Lol

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

    Tim can you make more web development tutorials using flask, Django

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

    Love the videos! Too bad there are not more

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

    Thanks for the video! I'm missing one thing - if the stack always "cleans itself" starting from the top, what happens to unused variables deeper into the stack? Does the program always have to wait for the last function to stop running before it can start cleaning the stack?
    To illustrate this - let's say we have a program that has hundreds of variables, each of which will take one place in the stack. We've done whatever we needed with them, but we still have one variable at the bottom that we aren't finished with. Then, we use that last variable in a loop that will take, I don't know, 2 minutes (the point is it's a calculation heavy process). All those variables that came before it are still stuck in the stack and continue taking place in memory.
    Does something like this often happen in practice? Is it a common way to make a badly optimized program that uses too much RAM? Obviously hundreds of variables with constant values will probably not do anything to modern computers, but you get the point. I'm guessing that a language would give us a way to force-clean up the stack before we decided to run that loop?

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

      This is a good question that confused me and a few other people i know when i started programming.
      In moat languages you can think of a stack as the space between { in here } brackets. Not every program uses them but most do.
      If you declare a variable there it is tied to that stack. If you start creating stacks inside stacks
      { var A { var B } }
      Then both values A and B live the exact same time. However since we are not using A in B's scope and we aren't using A after B's scope theoretical the compiler can change the scope to this.
      {Var A } { var B}
      Meaning we never have A and B taking up more memory then it needs to be.
      However there is more to the answer that may make it more complicated. In theory you want to declare variable only as you need them in the shortest lifetime possible.
      Hopefully that made sense and answered your question.
      If you want i can talk a bit more about stack frames and stack pointers if you want.

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

    This is a good video!

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

    Hey tim thanks for the video. Also I'm going to check out your programming expert school. Again thanks.

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

      Just got the course. If I have any questions contact you or is there a discord?

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

    非常好视频,爱来自瓷器❤️

  • @galeontiger
    @galeontiger 5 месяцев назад +1

    Why not use let mut string instead of let string = string::from? Is there a difference between these 2? I believe they are both mutable

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

    So, when I redeclare a variable to change it's type like this:
    let a: i32 = -5;
    let a: u32 = 7;
    Is it reasigned in the stack or popped and recreated? And if it is recreated, it may not be the last one on the stack right?

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

      Actually neither! When you redeclare a variable with the same name, you are doing "variable shadowing". Shadowing occurs when you create a new variable with the same name as the previous one, but it's a separate entity with its own storage. Therefore, the first "a" variable is allocated on the stack and when declaring the second "a" variable, it's also allocated on the stack, they both will exist until the end of the scope, but the first "a" variable is inaccessible because of the shadowing.

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

    He confused fixed-size with fixed-value.
    "let x = 2" is both fixed-size(i32) and fixed-value => stored on the stack, but also...
    "let mut x = 2; x = 3" is still the same size(i32) => still stored on the stack.
    Quoting from the book
    "All data stored on the stack must have a known, fixed size. Data with an unknown size at compile time or a size that might change must be stored on the heap instead."

  •  Год назад

    I would like to see the heap and stack memory in real time on my debug session. Do you know a tool?

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

    Is the rust playlist completed (as needed to start rust)

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

    Hi Tim, just want to ask, will you describe concept of code management for rust?
    I'm from Java developer, trying rust, but couldn't figure how we will separate codes and package?

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

    I wonder if Rust uses something similar to C++ short string optimization, in which case, everything you said about the string is wrong just because it is a short string.

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

    What is wrong with the subtitles?

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

    Wonderfull!!!

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

    Where is the next video of this series :/?

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

    Why is this playlist dead and no upcoming videos missing the videos man please make some videos

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

    Is this the last vid?

  • @LorenzoFoschi-on3fe
    @LorenzoFoschi-on3fe Год назад +1

    Is this series stopped? :(

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

    Waiting for the next on so muchhhhhhhhhhhhh :(

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

    This gives me C flashbacks

    • @luigi-fan554
      @luigi-fan554 2 года назад +1

      All of Rust is basically C on steroids

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

    will " let mut string = "hello"; " be on the heap????

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

    Hi when will the next video be ready? Thanks in advance

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

    Hey Tim 👋 can I have the name of the app you use for making your vids

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

    Next video? when coming? Tutorial # 10 Ownerships???

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

    when will be the next one? please continue hehe

  • @jedediah-fanuel
    @jedediah-fanuel 2 года назад

    The red font color seems a little bit less contrast to the background.

  • @ആറ്റിൽകളഞ്ഞപൂച്ചകുഞ്ഞു

    Bro is this series finished

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

    Can you please make your own wordle with a tutorial? Thanks.

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

    it looks like the caption file for episode 8 got uploaded for this one

  • @TruePakistani-od3uf
    @TruePakistani-od3uf 3 месяца назад

    Why everyone skips topic of loops is it really hard or what ? I never used rust. I call myself beginner-1.

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

    After 9 months - Still waiting for #10 - Ownership

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

      Or I guess I need to learn rust from some other youtuber.

  • @skubed007
    @skubed007 8 месяцев назад +1

    where is the next vid???

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

    still waiting rust tutorial-ownership

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

    still waiting for the "ownership" video :(