The High Performance Types You Ignored for Years in .NET

preview_player
Показать описание


Hello, everybody, I'm Nick, and in this video, I will show you a type that we had in C# and .NET since .NET Framework 2 that can offer similar benefits to the Span type. I will explain what it is, how it works and why it might still be relevant if you're stuck in an old .NET version.

Don't forget to comment, like and subscribe :)

Social Media:

#csharp #dotnet
Рекомендации по теме
Комментарии
Автор

Good to know. I'm stuck with a Framework 4.0 codebase (yes, that's a ".0") and having something that can serve the place of Span<T> is really nice.

gctypo
Автор

Thanks, stuck in framework 4.8 so this will help!

JakobStrasser
Автор

Thank you so much! I'm reading & coding with book C# 10 in a Nutshell, and this Span thing comes in Chap. 23. I'll get there soon!

AndyNeko
Автор

We have three names:
Nick
Rick
**some pause**
Richard

k_pavel
Автор

Thank you @Nick, I still work on projects in .NET 4.x and I didn't even know this ArraySegment even existed before.

IronTeddyBear
Автор

Bought your course to support you. Always learn something interesting from your videos. Best person on Youtube for C# stuff. Thank you!

reikooters
Автор

Thanks for this I wasn’t aware of either. I’m a noob but you’ve taught me a lot

saymehname
Автор

"Fun" fact: in Java every String is a Span over internal shared char array. This way substring was blazing fast, but it led to many memory leaks because GC was unable to free unused parts of that char array.

peceed
Автор

Didn´t knew ArraySegment and StringSegment, but as we already switched to .NET 7, we already use span for all other cases.
But what about you a case where you need to remove some items in a internally stored collection and you have a method "bool RemoveItems(params IItem items);". It would not make sense to pass down a ReadOnlySpan<IItem> as argument instead isnt´t it?

Fnalspace
Автор

ArraySegment is really nice when the byref-like nature of Span is something you cannot work around, like in an "out" parameter, a class field, generics etc. The proper counterpart to Span would be Memory there, but ArraySegment just sounds nicer.

IllidanS
Автор

Nick, please make a video about finding bottlenecks in high-load applications and how we should approach them when it is in production. How we should find out why our app running slow on high-load

Pouya..
Автор

It would be interesting to run the benchmark on struct and class. Wouldn't decrease the benefit as class are supposed to be passed by ref?

yobofunk
Автор

Can you use spans only for sequencial items? That if you enumeratithhe there you cannot to AsSpan afterwards?

garcipat
Автор

Instead of AsSpan().Slice(...), calling AsSpan overload which takes a range parameter should be even faster

carmineos
Автор

Nice video. :)
I am curious about your Benchmarks.cs file. Is it accessible from somewhere?

dejowe
Автор

Spans will become a lot better when collection expressions arrive in C# 12.

Span<int> ints = [1, 2, 3]; // will be stack-allocated

modernkennnern
Автор

Excellent content. I am always going to your videos to get great C# information, which is my preferred language. However, I have been wanting to get into ML with C#, but python seems to be dominant in this field. How do you feel about this subject. I don't particularly want to learn python, but I may have to. I just love C# so much, it is a shame I would need to switch.

PatrickHoodDaniel
Автор

Can be very useful especially if you are following functional programming practices: your data is immutable.

pawelwelsberg
Автор

Wouldn't Take(3) without the ToArray be similarly performant? I thought you'd show that as a comparison too, and now I'm curious how it compares.

pavlindrom
Автор

Hello, this is Nick Spanchap. Today we talk about Spanlike structures.

Haapavuo