Span of T vs. Memory of T

2024 ж. 13 Мам.
4 970 Рет қаралды

What's the difference between Span of T and Memory of T? My goal is not to tell you how awesome they are, but to get you over the hump of understanding how they work. I cover what they do and why, along with some description of their internals. Finally, I discuss what the owner consumer model is, and why it's relevant to Memory of T.
Blog:
betterwithcode.com/
LinkedIn:
/ jeff-zuerlein-2aa67b7
00:00 Introduction
00:53 What Are Spans and Memory
01:47 Definition of Span
02:29 Reference Structs
03:40 Fast Spans
04:07 Slow Spans
04:55 Memory of T Definition
05:38 How to use Spans with Memory
07:06 Ownershp / Consumer
09:16 Closing

Пікірлер
  • Great! Thanks. This channel deserves much more subscribers. Please keep up the good work!

    @timeless-sg@timeless-sg14 күн бұрын
    • Much appreciated!

      @JeffZuerlein@JeffZuerlein14 күн бұрын
  • Really really like the tiitbits you are making... Nowadays because of things I am getting pushed away from programming but these really bring back memories... Ty! Please keep publishing

    @bhatsanket@bhatsanket20 күн бұрын
    • That's so nice to hear! I've always loved the "internals" stuff, so it feels great to share with others.

      @JeffZuerlein@JeffZuerlein20 күн бұрын
  • Great explanations!

    @kudretkurt3832@kudretkurt38323 ай бұрын
    • Thank you!

      @JeffZuerlein@JeffZuerlein2 ай бұрын
  • Nice video with great details, all the best.

    @amrswalha@amrswalha13 күн бұрын
    • Thank you for the supportive comments! I'm really enjoying it.

      @JeffZuerlein@JeffZuerlein13 күн бұрын
  • Good stuff sir. Keep up the good work.

    @oldgraycoder@oldgraycoder2 ай бұрын
    • I appreciate hearing that, and I will.

      @JeffZuerlein@JeffZuerlein2 ай бұрын
  • Before this video I was thinking that I understand C#.... After this video I don't understand even heap and stack :D But thanks for sharing! Great video that pushes me (and pretty sure also other people) to learn new things!

    13 күн бұрын
    • But let me ask you.... In high performance application, like game development (like Unity) - it is good to know Spans/Memory of ? Like when I need to calculate "millions" of data (position, rotation, etc...) with maximum performance - I must use these right ? (must.... Like.... I should to!)

      13 күн бұрын
    • I haven’t written any games since I was using a C-64😂

      @JeffZuerlein@JeffZuerlein13 күн бұрын
    • I can imagine them being out to use in a game.

      @JeffZuerlein@JeffZuerlein13 күн бұрын
  • Nice video. Please could you do some videos on collection expression and type aliases, including Vectors and Intrinsics in C#?

    @obinnaokafor6252@obinnaokafor62524 күн бұрын
    • Thank you! I’m curious what’s you use case for Vector of T?

      @JeffZuerlein@JeffZuerlein4 күн бұрын
    • @@JeffZuerlein used in computation and machine learning as well gaming

      @obinnaokafor6252@obinnaokafor62524 күн бұрын
  • Turning our code into pretzels to safeguard memory access and housekeeping ... makes me want to return to C++ for the truly low-level work.

    @kenbrady119@kenbrady11913 күн бұрын
    • I understand that feeling. I don’t think spans and memory are for every project. I see them as a special tool for a special situation. When perf matters, it’s nice to know you have the option.

      @JeffZuerlein@JeffZuerlein13 күн бұрын
  • And there goes yet another major selling point of C# into the garbage collector. Being a native C and C++ speaker this video makes me very happy, as I can now make even more fun of my C# colleagues. From many points of view this span stuff is just hilarious. And, for the record, it is well explained in the video. Nothing wrong with that.

    @groenrechts5948@groenrechts594810 күн бұрын
    • Making fun of *any* programming language is for junior developers. Seniors use each to their strengths. Span allows for low-level optimizations in high-performance scenarios, without sacrificing all the benefits of C#, like type- and memory-safety. Span comes with a lot of safe-guards, while C++ is *always* low-level, giving you more "freedom" but also more risk.

      @mar_sze@mar_sze9 күн бұрын
    • @@mar_sze Question: Why should I not make fun of programming languages? They all have ridiculous features/notation/etc. Being allowed to use almost any date-type in an if-statement in C is hilarious, not to mention while loops intertwined with switch statements. Notation in C++ to remain backward compatible is sometimes ugly as hell and oftentimes super confusing for novices. Object oriented programming in Fortran90, what a joke it is. And so is C# filled with features that can be frowned upon. You see, as a senior developer I make fun of these things to remind people that programming languages are like a buffet where you should choose wisely what to eat and what not.

      @groenrechts5948@groenrechts59489 күн бұрын
    • There is plenty of code I like to make fun of…It has one author…Me. Over the years I’ve written plenty of programs that solved a problem, but suffered from many faults. It might look ill conceived, but that’s ok, it got the job done, and I got better because of it.

      @JeffZuerlein@JeffZuerlein8 күн бұрын
    • Trade offs…It’s always a trade off. Everytime I interview someone for a position, I tell them I like working in a collegial team. I want to hear their ideas, and I want them to tell me when they think I’m wrong. At the end of the discussion, I expect we’ll both have learned something. There is a lot of value in perspective, and seeing the trade offs.

      @JeffZuerlein@JeffZuerlein8 күн бұрын
    • ​@@JeffZuerlein Yes, trade offs are key, but oftentimes programmers have almost religious feelings about their 'holy' language. I used to have similar feelings decades ago, so I do understand, but I simply don't share this religious point of view anymore. And, for the record, the fact that I am a native C and C++ speaker does not imply anything. I am a native Dutch speaker as well, but I don't regard Dutch as the best language in the world. Not even close. But I can order a pizza in Dutch, and I can say Groningen and Scheveningen with the correct pronunciation. That's skill you see, very hard to master, but it is not an important skill. Junior programmers can hotly debate things in terms of 'better' and 'worse', whereas they should ask a bit more the 'what is it that actually matters' question. What are the true objectives of the project? On-time delivery? Performance? Maintainability? Flexibility? Being able to run on an FPGA? You can't have it all you know. Trade off it is, and I would like to know where the focus lies before I accept a position in my virtual job interview with you. This would be a fun discussion for sure, and we both might indeed learn something. Too bad I already have the best job in the world.

      @groenrechts5948@groenrechts59488 күн бұрын
KZhead