The Fastest Way To Work With Lists in C#! | .NET Tips 6

preview_player
Показать описание
Work with Lists in C# and .NET as fast as possible!
Рекомендации по теме
Комментарии
Автор

C# programmers - be very careful with that array!
C++ programmers - what is careful?

xxdeadmonkxx
Автор

Phew, I thought you were going to use reflection to get the internal list!

EdKolis
Автор

Advice in the category of "this is cool but NEVER do this"

LCTesla
Автор

it would be nice to add the senario we should use this type of techniques.

leulgirma
Автор

It's faster but you have to be careful. Any modification will create a new internal array and your span will no longer point to the right element in the memory. This is useful ONLY if you work with lists that have static pointer and have to loop huge arrays (I would say order of 500 million to billion or more). DO NOT do this for small arrays !!!! Difference is measured in billionth part of a second.

SimpMcSimpy
Автор

Thank you Nick for improving our C# skills!

smwnl
Автор

Look like a potential for Undefined Behavior in Managed Language

yuitachibana
Автор

Premature optimization. You really shouldn’t be doing this unless you are in the 1% of 1% of special case applications.

minnesotasteve
Автор

I have noticed in most cases AI to be helpful in explaining things like code or concepts than
do the whole problem for you.

First example, if you ask ai to solve one of the beginner exercise in skill foundry you will notice they solve it under program classic and static keyword which can confuse the beginners even more

shafialanower
Автор

Is span of T much faster than list or ienum of T? If so, have you done a video about when it’s faster or why?

StephenOwen
Автор

What is the use case for this? Why should it be preferred?

JimmieZaccai
Автор

Why would you want to iterate through a Span instead of a List/Array?

TommyTheITGuy
Автор

How do you see that "IL code"? Is that an VS extension?

divanvanzyl
Автор

How exactly is it faster? Not doubting just wondering how it works. I would've thought that with C# lists being contiguous in memory it would be about as fast as you can get

Sweenus
Автор

Haha, I would say this is a benefit, that it won't throw an exception.

kyryllvlasiuk
Автор

I’m sick of these guys “tips and tricks” that never represent any real world scenarios

IamPali
Автор

how about just don't do this at all

ad
Автор

That will never get through a code review.

bob-xmny
Автор

Wait, span is a structure pushed onto the stack. The array in the list is on the heap.
When you convert a list to a span, clr must copy the bytes from the heap to the stack. Right ?
And for the CPU, access to the stack or heap is the same thing. When the CPU predictor realizes that a memory address is in a register, it copies the bytes into the cache. Where can you profit from performance with this type?

The only benefit of arranging data on the stack, it seems to me, is that you no need to call the memory allocator and that after exiting the function, the data is automatically lost.

vifvrTtbvmFtbyrM_Q
Автор

If you have 10 items in list, why care ?

xury
visit shbcf.ru