Zig Master: Memory in Practice

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

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

  • @slugbtye
    @slugbtye 6 месяцев назад +8

    This is the clearest demonstration of memory I have ever seen, you are a brilliant educator!

  • @alonelyproducer663
    @alonelyproducer663 6 месяцев назад +10

    Hey, i just wanted to thank you for your videos about Zig. You are more or less the only source on youtube to learn zig. So, thank you very very much. Please continue the series!!!
    ❤❤❤

  • @tigranrostomyan9231
    @tigranrostomyan9231 6 месяцев назад +4

    I DON’T KNOW why this video has only 300 views… This is such great content. Thank you so much!

  • @pietraderdetective8953
    @pietraderdetective8953 6 месяцев назад +5

    Dude the builder, you're like a beacon of light for those newcomers in Zig.
    Thank you for the series, this is amazing!

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

    Pointers, memory, RAII... Rust is *always* one step ahead.

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

      Rust's memory management is indeed revolutionary and advanced. But for some really low-level projects, you end up with most of your code in unsafe blocks and that turns out to not feel as Rusty.

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

      @@dudethebuilder I was just baiting 🙃 I use Zig and I prefer it over Rust for simplicity and few other design decisions :D Still, thanks for your answer.

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

    I am curious! Why is it legal in Zig to return a reference to a var that is allocated on the stack? Isn't this always wrong? There must be important situations that require this not to be an error...

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

      I remember seeing a discussion on the Zig project GitHub mentioning that it's planned to be an error in the future, but I'm not sure if that's still the plan. Right now the main goal is compile speed and incremental compilation, so maybe if this type of analysis gets in the way of that, they'll hold it off.

  • @RobertVoogdgeert
    @RobertVoogdgeert 6 месяцев назад +1

    Thanks again for yet another beautiful and helpful tutorial. Running the c function twice, as in your video results in the exact same addresses as well as values when I run it: ptr_to_const: 10da430f7 = 3, ptr_to_var: 7ff7b2585ec6 = 99 . Is this because of the version of Zig I'm running: 0.13.0-dev.46+3648d7df1 ? Point is, the value of the var doesn't change are the first function call has exited. Could you replicate this?

    • @dudethebuilder
      @dudethebuilder  6 месяцев назад +1

      Yes this is why returning a pointer to stack memory is considered "undefined behavior," because the results are unpredictable. You may get the same value, or you may get anything else. This can vary beteween operating systems and build modes. On macOS, I always get 0 in debug mode and varying values in the different release modes. On Linux, I always get different values no matter what the build mode. You can change the build mode by adding -Doptimize=ReleaseSafe (or ReleaseFast or ReleaseSmall) to zig build run.