Value & Reference types in C#. Write Better Code!

preview_player
Показать описание
Value vs reference types. Stack vs heap. These are fundamental concepts to understand if you wish to write performant code. Learn the characteristics of value and reference types and how they're allocated to memory. Learn how StackOverflowException occurs and how to fix and prevent them.

=========

0:00 - whatever, intro I guess
0:37 - value types / structs
2:00 - reference type / class
3:00 - stack & heap
3:27 - stack example
5:57 - heap example
8:47 - when to use one over the other
11:30 fix StackOverflowException
13:15 - Bonus: strings
Рекомендации по теме
Комментарии
Автор

Damn, I miss spoke a few times in this recording so there are a few annotations! Don't shoot me guys

Also, explode this thread

Tarodev
Автор

Finally, I understood the principle of Stack and Heap, You Are A Legend

syluxdev
Автор

I was not ready for this video 1 year ago! Came back today and I think I understand my games poorer performance issues better...I likely still need to watch this video like 5 more times
XD

JW-uuje
Автор

Finally now i know what does the stack overflow error mean.

kawaiianthony
Автор

You're great at making complicated concepts easy to understand, thank you!

frankkubrick
Автор

this is super useful. i've been using c# for over a year and never knew the difference. thanks a lot!

Firebreak_
Автор

Awesome video man! I've always been a little unsure of the differences between the two and when to use structs vs classes but you explained it in a way that made complete sense. The animated diagrams you showed of the Stack and Heap were so useful!

Destructivepurpose
Автор

This tied some of my disparate knowledge bits together, making me a better man

MrShark-quxx
Автор

Man, you are a truly a savior to my C# Unity knowledge !!!

vietanhnguyen
Автор

Now I know what a stack overflow is. I feel like a computer engineer now !!

kyleme
Автор

One rule I usually follow is to use structs to store data that is short lived and either read-only or independent of other copies. Some good examples are event arguments, their main function is to return data to multiple places and be deallocated right after. If you are making a game with many events firing every frame, classes will just overwork the GC, but with a struct there won't be any GC and the stack allocation is minimal.

WagnerGFX
Автор

The visuals looked like they took a lot of work to create, but they really helped me understand what's happening under the hood. Thank you!

jadonmullinex
Автор

Your illustrations of the stack and heap allocations where didactically perfect!

jbmgil
Автор

Been coding in unity for like 5 years now. THis is still not just beyond the scope of what my brain can access, but im afraid it will forever be.

dago
Автор

Nice to have finally found a channel that gets down to the nitty griddy of coding! Most of these tutorial channels are honestly just pointing out fairly obvious things u can find out on your own... And the big problem with unity related forum searches is, that most of the users are entry level devs and don't understand longevity, or even the questions being asked. Hopefully your content will provide some much needed substance to this void of information! (Ok, that sounded pretty harsh on the other channels, but appreciate the 'deep dive' aspect!)

Miguellmkuutti
Автор

Fantastic explanation. I learned a lot. Sounds like if your initializing a variable with new it's going on the heap. I never understood why some needed this and some did not now its perfectly clear!

overrideFunction
Автор

Amazing content man, please never stop, if I wasn't currently unemployed you would be my debut patreon subscription in a heartbeat.

alexgeeves
Автор

thanks I watched the whole thing but I want to hammer these topics into my head so ima come rewatch later on

doge
Автор

Great video. There is a lot of advice out there regarding the dangers of heap allocation and garbage collection, so it's good to see one that covers the "other side" of the balance.

danieletorrigiani
Автор

Watched this 2 days ago and today I finally fixed a bug caused by interpreting this stuff wrong last week lol

DevDunkStudio