Тёмный

Stackalloc and Spans 

Coding Tutorials
Подписаться 15 тыс.
Просмотров 10 тыс.
50% 1

Опубликовано:

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 32   
@CodingTutorialsAreGo
@CodingTutorialsAreGo Год назад
Do you have performance problems because of heap allocation? Let me know in the comments. Source code available at: github.com/JasperKent/Spans-and-stackalloc Remember to subscribe at ru-vid.com/show-UCqWQzlUDdllnLmtgfSgYTCA And if you liked the video, click the 👍.
@RiversJ
@RiversJ Год назад
My viewpoint is that heap alloc is pure evil and should only be done as a setup step and almost never as part of routine runtime unless storing data. But I'm a graphics/rendering programmer so that means my environment is rather radically different from the norm!
@PeacefulMindss
@PeacefulMindss Год назад
I haven't seen anyone explaining Spans this simple and clear way, thank you Sir.
@meredoth2725
@meredoth2725 Год назад
Amazing video as always! A small correction, at 8:24, you say that a list may not be a contiguous space in memory, actually the list will always be a contiguous space in memory because it is just a wrapper over the c# array, the reason is that when the list grows bigger than its initial length , it will create a new array and copy the old one, but the span will still point to the space in memory where the previous array was . That's why we have the CollectionsMarshal.AsSpan(List) Method, but is only safe to use when we are sure that the list won't relocate the array.
@CodingTutorialsAreGo
@CodingTutorialsAreGo Год назад
Absolutely right.
@alangamedeveloper7820
@alangamedeveloper7820 Год назад
Your videos are awesome. I wish everybody would watch them and update their C# knowledge to modern practices. Unfortunately many people are happy to bump .NET to 7 and C# to preview but didn't bump their coding so I still see recent C# that looks very old. Also, in your fast parser you could very easily determine the starts/ends of each number and pass just that section of the Span to the double parser. That should definitely yield more time improvements without all that copying. Keep up the awesome work!
@CodingTutorialsAreGo
@CodingTutorialsAreGo Год назад
Yeah, there's more room for optimization, but getting things off the heap is the big one.
@conlethmackle4062
@conlethmackle4062 3 месяца назад
Your tutorials are in my opinion easily the most informative of the C# Tutorial series available. You deserve far more subscribers. I always come here first to improve my understanding of C# fundementals
@robertmrobo8954
@robertmrobo8954 Год назад
A very good example to show to a junior when explaining how evil early optimazation can be. Just as the speaker said, only do this when you really-really have to. 😊
@CodingTutorialsAreGo
@CodingTutorialsAreGo Год назад
Absolutely. I've never needed to do this is real life.
@Kolmix15
@Kolmix15 Год назад
I love your content! It's so clearly explained. Thank you sir
@mumk
@mumk Год назад
Thanks sir, your explanations are crystal clear. Absolutely loving the video
@nikolaperisic37
@nikolaperisic37 18 дней назад
Wow. This was sooo useful. Thank you! You got a new subscriber
@mihailpeykov
@mihailpeykov 4 месяца назад
All was good and informative up to the point you implement the "fast" parser using spans. That one was not good. You don't need to copy each number's characters to a stack allocated buffer just to pass them to double.Parse(Span) - you could just do it with spans pointing inside the original string. That would avoid the risks of stack overflow you mentioned and will be slightly faster.
@davidwhite2011
@davidwhite2011 Год назад
Another great edition of Coding Tutorials.!
@Schnickalodeon
@Schnickalodeon Год назад
Once again a perfectly explained video :) Thank you!
@dizmo..
@dizmo.. 11 месяцев назад
Sir, this tutorial is amazing, just like your costume!)
@pharoah327
@pharoah327 5 месяцев назад
How can we return a Span from a function? Or any value type that has more than one field in it? In my understanding, when we return from a function, we pop the activation record, then pop the return address and follow it back to the caller. Since this pops the span from the stack, how do we use it in the calling function? With heap allocation, we can store a pointer in a register and use that to refer to the memory. Yet if we store a stack pointer to now unallocated memory, that wouldn't be good. So I'm really confused on how this would be used if returned from a function.
@10Totti
@10Totti Год назад
Thanks!
@jphvnet
@jphvnet 3 месяца назад
Finally cs gets c++ style hard to read when talking about optimized code... Nice
@rauberhotzenplotz7722
@rauberhotzenplotz7722 9 месяцев назад
Are you sure that you need 'number.Fill' at all? After the stackalloc, 'number' should contain only #0 chars, if you don't have a SkipLocalsInit attribute. You could pass a slice of 'number' between zero and 'pos' to double.Parse.
@subindavid4343
@subindavid4343 Год назад
This is what is called "Perfection and Dedication". Thank you sir.
@Aweklin
@Aweklin 3 месяца назад
Sooooo clear. Thanks a lot for this.
@aamirali8114
@aamirali8114 10 месяцев назад
i couldn't understand the benefit of Span if i am able to modify in copy array and changes are reflected in original array too then whats the use i want my copied array changes shouldn't be modified in original array.
@CodingTutorialsAreGo
@CodingTutorialsAreGo 10 месяцев назад
The benefit is that you save the performance overhead of doing a copy. The modification is a side-effect that you may or may not want. If you don't want it, you can either use a ReadonlySpan and prevent changes at all, or take the performance hit of doing a copy.
@thewelder3538
@thewelder3538 20 дней назад
What you're saying is NOT true, at least to my understanding. If you had this... List t = []; If you started adding bytes to the list, are you saying that they're not guaranteed to be contiguous? I think you'll find that they will be. So you should be able to span over a list of bytes... This is why C# is a bit shitty in its implementation. There are no ambiguities like this in C++.
@tiagocosta9113
@tiagocosta9113 2 месяца назад
Conclusion: Write C code to be more faster and don't get heap allocation
@shoooozzzz
@shoooozzzz 7 месяцев назад
So happy I found your channel! Great video. I plan on subscribing and going through your backlog as this is a great explanation of Span
@nouchance
@nouchance Год назад
THANK You Sir
@10Totti
@10Totti Год назад
Do you use also Blazor ?
@CodingTutorialsAreGo
@CodingTutorialsAreGo Год назад
Sometimes, though it's not as widely used as things like Angular or React.
Далее
What is Span in C# and why you should be using it
15:15
.NET Core Garbage Collection
14:54
Просмотров 24 тыс.
История Hamster Kombat ⚡️ Hamster Academy
04:14
Офицер, я всё объясню
01:00
Просмотров 3 млн
С какого года вы со мной?
00:13
Просмотров 148 тыс.
The Fastest Way to Modify a List in C# | Coding Demo
10:30
The weirdest way to loop in C# is also the fastest
12:55
Blazor RenderFragment
23:11
Просмотров 2 тыс.
5 (Extreme) Performance Tips in C#
12:26
Просмотров 75 тыс.
6 C# keywords you (probably) never had to use
17:33
Просмотров 68 тыс.
Span of T vs. Memory of T
9:44
Просмотров 6 тыс.
LINQ's INSANE Improvements in .NET 9
11:26
Просмотров 48 тыс.
История Hamster Kombat ⚡️ Hamster Academy
04:14