Arrays vs Lists

preview_player
Показать описание
What do Santa Claus and the .NET runtime have in common? When they make a list, they check it twice.

Topics include:
- C# collection performance
- Comparing generic lists and arrays in .NET
- Underlying collection structures
- Collection benchmarking
Рекомендации по теме
Комментарии
Автор

What's your worst performance mistake? Let me know in the comments.
And if you liked the video, click the 👍.

CodingTutorialsAreGo
Автор

Your channel is goldmine! Huge respect

Mati
Автор

I found your channel recently, but I surprised of quality of your videos. Thx for your tutorials 😊

kurumi
Автор

Thank you for the explanation. Always learn things from you ❤

imikhan
Автор

The trade-off at the end of the video can be harmful in terms of GC. If you call this code many times, GC time can be longer than iteration over the list with the double check. Especially if you have a web app scenario, having 100 slightly slower requests can be better than having 99 faster requests and one really slow one (when GC happens), for example, if you have a timeout at the client side.

MrXzxzxc
Автор

Something like a open/closed state of a List would be useful to have the best of both worlds.
In open state it would act as a regular List and in closed state would be have a fixed size like an Array. To have .closed() method which would change its internal bool state and free up unassigned memory.

tayablackrose
Автор

In hot paths the difference can be between meeting or not meeting requirements.

RiversJ
Автор

I got such message when running program. Please, give me a tip what's going on?
// Validating benchmarks:
Assembly ListVersusArray which defines benchmarks is non-optimized
Benchmark was built without enabled (most probably a DEBUG configuration). Please, build it in RELEASE.

Maxim_Grekov
Автор

arrays vs dicts(hash tables), who wins at performance and speed ?

muireachgriogalach
Автор

Tell me please Jasper, is this example specific only to VS2022?

Maxim_Grekov
Автор

I recommend *against* doing this, but if anyone is curious how you would read array elements without bounds checks, like this:

int[] arr = new int[10];

// get reference to element at [0] without bounds checks
ref int first = ref

// add 4 elements to the reference, making a new reference that points to element at [4]
// then dereference it, now you read the fifth element without bounds checks
int fifth = Unsafe.Add(ref first, 4);

That being said though, if you write a *for* loop for the array, the bounds checks should be compiled away anyway.

petrusion
visit shbcf.ru