Span of T vs. Memory of T

  Рет қаралды 6,053

Jeff Zuerlein

Jeff Zuerlein

Күн бұрын

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

Пікірлер: 25
@timeless-sg
@timeless-sg 25 күн бұрын
Great! Thanks. This channel deserves much more subscribers. Please keep up the good work!
@JeffZuerlein
@JeffZuerlein 25 күн бұрын
Much appreciated!
25 күн бұрын
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!
25 күн бұрын
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!)
@JeffZuerlein
@JeffZuerlein 25 күн бұрын
I haven’t written any games since I was using a C-64😂
@JeffZuerlein
@JeffZuerlein 25 күн бұрын
I can imagine them being out to use in a game.
@bhatsanket
@bhatsanket Ай бұрын
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
@JeffZuerlein
@JeffZuerlein Ай бұрын
That's so nice to hear! I've always loved the "internals" stuff, so it feels great to share with others.
@amrswalha
@amrswalha 25 күн бұрын
Nice video with great details, all the best.
@JeffZuerlein
@JeffZuerlein 25 күн бұрын
Thank you for the supportive comments! I'm really enjoying it.
@kudretkurt3832
@kudretkurt3832 3 ай бұрын
Great explanations!
@JeffZuerlein
@JeffZuerlein 3 ай бұрын
Thank you!
@obinnaokafor6252
@obinnaokafor6252 16 күн бұрын
Nice video. Please could you do some videos on collection expression and type aliases, including Vectors and Intrinsics in C#?
@JeffZuerlein
@JeffZuerlein 16 күн бұрын
Thank you! I’m curious what’s you use case for Vector of T?
@obinnaokafor6252
@obinnaokafor6252 16 күн бұрын
@@JeffZuerlein used in computation and machine learning as well gaming
@oldgraycoder
@oldgraycoder 2 ай бұрын
Good stuff sir. Keep up the good work.
@JeffZuerlein
@JeffZuerlein 2 ай бұрын
I appreciate hearing that, and I will.
@kenbrady119
@kenbrady119 25 күн бұрын
Turning our code into pretzels to safeguard memory access and housekeeping ... makes me want to return to C++ for the truly low-level work.
@JeffZuerlein
@JeffZuerlein 25 күн бұрын
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.
@groenrechts5948
@groenrechts5948 22 күн бұрын
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.
@mar_sze
@mar_sze 21 күн бұрын
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.
@groenrechts5948
@groenrechts5948 21 күн бұрын
@@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.
@JeffZuerlein
@JeffZuerlein 20 күн бұрын
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
@JeffZuerlein 20 күн бұрын
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.
@groenrechts5948
@groenrechts5948 20 күн бұрын
​@@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.
A Complete .NET Developer's Guide to Span with Stephen Toub
1:02:48
Writing C# without allocating ANY memory
19:36
Nick Chapsas
Рет қаралды 143 М.
Glow Stick Secret (part 2) 😱 #shorts
00:33
Mr DegrEE
Рет қаралды 54 МЛН
Trágico final :(
01:00
Juan De Dios Pantoja
Рет қаралды 30 МЛН
КАРМАНЧИК 2 СЕЗОН 5 СЕРИЯ
27:21
Inter Production
Рет қаралды 450 М.
Understanding B-Trees: The Data Structure Behind Modern Databases
12:39
Python 3.12 Generics in a Nutshell
6:22
ArjanCodes
Рет қаралды 45 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2 МЛН
SQLite Uses ByteCode (And For Good Reason)
19:07
ThePrimeTime
Рет қаралды 79 М.
What is Span in C# and why you should be using it
15:15
Nick Chapsas
Рет қаралды 246 М.
Manage User Rights By Decorating Their Claims Identity
9:35
Jeff Zuerlein
Рет қаралды 2,8 М.
Stackalloc and Spans
30:17
Coding Tutorials
Рет қаралды 8 М.
5 Rules For DTOs
17:56
Ardalis
Рет қаралды 36 М.
The Fastest Way to Modify a List in C# | Coding Demo
10:30
Zoran Horvat
Рет қаралды 19 М.
Master the Design of Functional Types in C#
17:53
Zoran Horvat
Рет қаралды 10 М.
🤔Почему Samsung ПОМОГАЕТ Apple?
0:48
Technodeus
Рет қаралды 377 М.
Samsung or iPhone
0:19
rishton vines😇
Рет қаралды 8 МЛН
Дени против умной колонки😁
0:40
Deni & Mani
Рет қаралды 6 МЛН
Обманет ли МЕНЯ компьютерный мастер?
20:48
Харчевников
Рет қаралды 182 М.