.Net Memory Allocations and Performance

  Рет қаралды 32,814

Shiv Kumar

Shiv Kumar

Күн бұрын

Пікірлер: 122
@amadzarak7746
@amadzarak7746 29 күн бұрын
Ik this video is old, but the key concepts remain as relevant. Having to learn c# for my job and this video is a Godsent
@SatyendraRoutela
@SatyendraRoutela 4 жыл бұрын
I generally don't comment on videos but your videos are really awesome.
@Matlus
@Matlus 4 жыл бұрын
Thank you Satyendra for taking the time to let me know! it is much appreciated. Sorry for the delayed reply, somehow tour comment slipped by
@dhanasekar4520
@dhanasekar4520 3 жыл бұрын
you are giving this much of knowledge for no cost its incredible. thank you sir.
@Matlus
@Matlus 3 жыл бұрын
Thank you Dhanasekar! And you're welcome.
@jaysonknight
@jaysonknight 6 жыл бұрын
Great primer, I hope all of our teams have watched this or been versed in this. It would be great if you could cover string interning as well as this is a very important aspect of how strings are managed by the CLR, and changes how you describe string handling by the CLR by way of the intern pool.
@09FT9
@09FT9 3 жыл бұрын
The way you explain makes it so easy to understand this complex concept. If you ever write a book, I am going to be the first one to buy it!
@Matlus
@Matlus 3 жыл бұрын
Thank you for an inspiring and encouraging comment!
@himanshutyagi1205
@himanshutyagi1205 4 жыл бұрын
A clear visualisation of .net memory layout. Thanks Shiv for this nice video. Completed the 1st part, now going to complete the 2nd one.
@Matlus
@Matlus 4 жыл бұрын
So How was Part 2 Himanshu?
@himanshutyagi1205
@himanshutyagi1205 4 жыл бұрын
@@Matlus Amazing. Kudos to you for the way you explain everything in details.
@Matlus
@Matlus 4 жыл бұрын
@@himanshutyagi1205 Thank you! Appreciate the encouragement.
@garethevans9789
@garethevans9789 5 жыл бұрын
Superb video. You have a knack for getting the pace and depth just right. I also look forward to video 2.0!
@Matlus
@Matlus 4 жыл бұрын
Hi Gareth, Part 2 is now available, please take a look
@DevNerdKonradKokosa
@DevNerdKonradKokosa 3 жыл бұрын
If you find those topics interesting, feel free to watch my in-depth .NET GC Internals series at kzbin.info/aero/PLpUkQYy-K8Y-wYcDgDXKhfs6OT8fFQtVm 👀
@Matlus
@Matlus 2 жыл бұрын
Thank you Konrad! You have great content indeed!
@charankumar5633
@charankumar5633 2 жыл бұрын
I have been trying to understand properly on the memory allocation, finally I found one. Thanks for sharing this knowledge :)
@glaysonpatricio
@glaysonpatricio 2 жыл бұрын
The amount of details in your explanation is impressive!
@Matlus
@Matlus 2 жыл бұрын
Thank you! I'm happy to hear that you appreciate the details.
@sarbanjeet
@sarbanjeet Жыл бұрын
Thank you so much, I never know the difference between static object and allocation before.
@davidpike5959
@davidpike5959 4 жыл бұрын
Easily the best video I've seen on this topic, bookmarked. Great work, thank you.
@Matlus
@Matlus 4 жыл бұрын
Thank you David! There is a Part 2 to this one that I'm sure you'll enjoy as well.
@davidpike5959
@davidpike5959 4 жыл бұрын
@@Matlus Good man, i'm on it- thanks again :D
@kurnaPunk
@kurnaPunk 6 жыл бұрын
Fantastic video, part 2 pleeeeease!
@Matlus
@Matlus 4 жыл бұрын
@Nicholas Zhang, Part 2 is out. Have you watched it?
@19gauravmittal91
@19gauravmittal91 4 жыл бұрын
Amazing way of teaching with visualization. Please post about some latest tech like Micro-services.
@kevinm8865
@kevinm8865 3 жыл бұрын
Nice give and great presentation! I agree completely with your analogy of car driving. It amazes me how often, as an intermediate developer growing his skills, I come across senior devs and architects who haven't taken time out to understand the internals of their languages and tools. I don't expect everyone to dig deep into internals but in code reviews it's irritating when my code is questioned or called wrong because the reviewer lacks the detailed understanding of components /design and assume I'm wrong because I'm less experienced. As new frameworks and tools keep coming out, devs are less and less encouraged to understand and instead choose the easier route of finding/adding another dependency yo abstract the details away. This of course sometimes adds costs to the organization and in nearly all cases adds more complexity to the entire system and yet another possible point of failure.
@Matlus
@Matlus 3 жыл бұрын
Thank you Kevin! How true!! all of your observations match with mine as well. The dependencies, the not wanting to know how things actually work and not listening to a dev just because they have less experience than you etc. It's a sad state of affairs really. But if we each do our part, maybe we can collectively affect a change :).
@kevinm8865
@kevinm8865 3 жыл бұрын
@@Matlus So true! Thanks for the kind words and the education. New sub now!!
@Matlus
@Matlus 3 жыл бұрын
@@kevinm8865 Thank you for subscribing Kevin!. By the way, there is a part 2 to this video I think you'll enjoy as well.
@rakeshpathania829
@rakeshpathania829 4 жыл бұрын
Wao...you make my day @shiv .... I had a lot of confusion regarding memory management but now i have basic understanding of how things works under the hood......and i am looking forward for part 2....Thanks...:)
@Matlus
@Matlus 4 жыл бұрын
There is a part 2 Rakesh. You can find it here. kzbin.info/www/bejne/fZaTpayApsmbrrs
@saurabhchauhan232
@saurabhchauhan232 3 жыл бұрын
Excellent Presentation, Going to checkout part 2. 😀
@Matlus
@Matlus 3 жыл бұрын
Thank you Saurabh! I'm positive you'll like part 2 as well.
@saurabhchauhan232
@saurabhchauhan232 3 жыл бұрын
@@Matlus Honestly I tried watching it but it's too advance, and I understand very few things from it. Not your fault but I my self is not well enough to understand such beautiful talk.
@Matlus
@Matlus 3 жыл бұрын
@@saurabhchauhan232 Thank for the feedback Saurabh. Yes, Part 2 is quite a bit advanced and delves into the hardware, so it's not for everyone. Don't worry about it though. As you spend more time in software, you may start to understand (or have a need to understand) the hardware.
@DheerajKumarWebDetails
@DheerajKumarWebDetails 4 жыл бұрын
You are just awesome , subscribed for life time
@Matlus
@Matlus 4 жыл бұрын
Thank you Dheeraj!
@krishnanigalye1173
@krishnanigalye1173 4 жыл бұрын
Thank you for this video. Great in-depth explanation. Even before watching half of this video, I subscribed to your channel.
@Matlus
@Matlus 4 жыл бұрын
Thank you Krishna! And thank you for subscribing. There is a Part 2 of this video as well, be sure to watch that.
@skarpetky8590
@skarpetky8590 2 жыл бұрын
Hello Sir! Thank you sir! Your explanation is the best sir! You best of the best sir!
@Matlus
@Matlus 2 жыл бұрын
You are most welcome!
@bigbtripathi
@bigbtripathi 2 ай бұрын
Superb information. From where did you get this information ? Is it published by microsoft? Does the latest .net core framework uses the same principle ?
@lalithswarna2097
@lalithswarna2097 4 жыл бұрын
Awsome video!! the way you explained is pretty good. Wowww you have a great cinematic voice, i felt like watching a movie while learning :)
@Matlus
@Matlus 4 жыл бұрын
Thank you Lalit, for your kind words.
@techypd559
@techypd559 4 жыл бұрын
Hi Shiv..i really like the way you explain things. Need your help if you can explain proper way to debug production memory leak issues in WCF (.NET)
@Matlus
@Matlus 4 жыл бұрын
Hi Techy. Thank you! Looking for memory leaks is an VERY involved process, requiring an in-depth understanding of .NET and memory management. But you're go to have to start with getting a memory dump of the process while the problem is occurring. Visual Studio (new versions) do have the ability to open memory dumps, but you're going to have to learn to decipher what you're seeing as well. You can also use WinDbg and SonOfStrike. Of course prevention is better than cure. A lot of my videos in the Programming With Intent playlist show you what I have learnt as best practices over my career. Following those practices will prevent such issues to a large extent.
@dusanrychnovsky3837
@dusanrychnovsky3837 5 жыл бұрын
Great video, Shiv, thanks! The part 2 you mentioned isn't available yet, is it? Thank you
@Matlus
@Matlus 4 жыл бұрын
Hi Dušan, thank you! Yes, part 2 is now available.
@BobbyCannon
@BobbyCannon 4 жыл бұрын
"Hello Viewers" (bass, bass, all about that bass) - I was like woah...
@Matlus
@Matlus 4 жыл бұрын
Be sure to watch Part 2 of this one too Bobby
@LaurentLaborde
@LaurentLaborde 4 жыл бұрын
i had the same reaction :D
@EminoMeneko
@EminoMeneko 3 жыл бұрын
Actually too much bass is not good for speech ineligibility. Bass under 500 Hz shall be tamed Frequencies between 2 and 4 KHz shall be boosted.
@ArunKumar-ll9lo
@ArunKumar-ll9lo 4 жыл бұрын
Great session..Just wanted to clear one confusion..is array of integer value type..?
@Matlus
@Matlus 4 жыл бұрын
Thank you Arun!. An Array is a reference type. It doesn't matter what the Array is of.
@Trhnetesiuz
@Trhnetesiuz 3 жыл бұрын
Hello sir. Thanks a lot for your videos! I am a programming beginner and I learned so much from you. Might I suggest a small recommendation to make it even easier for us: - Share your code & resources in the video descriptions - Create small chapters within the video, so the users can easily jump from one part to another. Something like 0:00 Intro, 2:36 Basics etc. It would make the first time watching and specially revisiting the videos much easier!
@Matlus
@Matlus 3 жыл бұрын
Thank you for your comments Mar. I do share code for when I think code it relevant and I do put in Chapter parkers for when I think it's relevant also. The Chapter markers feature was not available earlier and so my older videos don't have chapter markers. But I'm guessing you feel that some videos are missing chapter markers :). I'll try and provide those for videos moving forward.
@tileq
@tileq 3 жыл бұрын
I think there is a mistake on the slide at 30:42. Type Object Pointer belongs to the object (same as Sync Block Index). Method table is part of Type object.
@Matlus
@Matlus 2 жыл бұрын
The Type object pointer is a pointer to the type instance. All objects will have a pointer and they'll all point to the same type instance. The slide could be wrong (I haven't seen it in a while) but as long as you get the concept :) There are two method tables. One for instance methods and one for static methods. Of course this is just a mental model to have the actual implementation is subject to change at any time.
@conchimxanhxanh255
@conchimxanhxanh255 4 жыл бұрын
What a wonderful video! Thanks a lot for all of your efforts doing this. Would you recommend any books relates to this topic in Dotnet? Thanks
@Matlus
@Matlus 4 жыл бұрын
Thank you Tran! Appreciate you taking the time to comment. I can't say I know of any books that describe things at this detail level.. Be sure to watch Part 2 as well!
@hydtechietalks3607
@hydtechietalks3607 3 жыл бұрын
www.pdfdrive.com/writing-high-performance-net-code-e195138098.html
@aaasd5526
@aaasd5526 6 жыл бұрын
I'm waiting for the second part! Great stuff
@Matlus
@Matlus 4 жыл бұрын
Aasad, part 2 is now available. Please check it out
@Sushilkumar-yq7iy
@Sushilkumar-yq7iy 4 жыл бұрын
Very well explain Sir. for .net core GC working has been changed like workstation gc and server gc works different. When run .Net core app inside container with limited memory allocation then programmer need to choose which gc should be used based on hardware allocation. Could you make a video of how gc working and memory management has been changed in.net core. Thanks 🙏
@Matlus
@Matlus 4 жыл бұрын
The choice of which GC to use is clear. Long running applications (like ASP.NET or Background services etc.) should use server GC. Desktop applications should use the workstation GC. The changes are well documented so unless there is something you don't understand (and you tell me) I don't see any value on making a video on this. This video explains what is going on under the hood so C# programmers can be smarter about how they write code and if they have issue, they'll be in a better place to determine what is causing the issue and how to potentially fix the issue. If you program correctly, you shouldn't have issues :)
@JonatanMachado
@JonatanMachado 5 жыл бұрын
Great Video! Looking forward to part 2.
@expertreviews1112
@expertreviews1112 2 жыл бұрын
Great content and really informative! Can you share further references where we can go deep in this topic?
@asutoshrao8316
@asutoshrao8316 4 жыл бұрын
Awsome explanation. Really enjoyed. Can you explained memory allocation in case of inheritance ? Some visuals will really help.
@Matlus
@Matlus 4 жыл бұрын
Every instance of an object will be allocated in a similar fashion. It makes no difference for inherited objects. Descendants are "complete" that is to say, it's not like there is allocation for the ancestor and another allocation for the descendant. The descendant is a complete object in and of itself and thus when it is allocated it is allocation in its entirety
@brianmikinski8984
@brianmikinski8984 6 жыл бұрын
This is great. Can't wait for part 2.
@Matlus
@Matlus 4 жыл бұрын
Hi Brian, part 2 is now available
@benjaminb.4043
@benjaminb.4043 6 жыл бұрын
@Shiv Kumar Hello! Absolutely fantastic video, learnt a lot! Do you still have plans to release the second part of the series?
@Matlus
@Matlus 6 жыл бұрын
@Benjamin B. Thank you! Yes I do plan to make Part 2. It's just taking longer than I expected due to work commitments.
@Matlus
@Matlus 4 жыл бұрын
Hi @Benjamin, part 2 is now available
@EminoMeneko
@EminoMeneko 3 жыл бұрын
Thank you for the video.
@Matlus
@Matlus 3 жыл бұрын
Thank you! And you're most welcome.
@HumbertoPereira1994
@HumbertoPereira1994 4 жыл бұрын
Fantastic Video!!!!!
@Matlus
@Matlus 4 жыл бұрын
Thank you Humberto!
@Matlus
@Matlus 4 жыл бұрын
Humberto, be sure to watch Part 2
@LilPozzer
@LilPozzer 3 жыл бұрын
Hope you'll get more than 10k subs!
@Matlus
@Matlus 2 жыл бұрын
I hope so too. Very close now!
@LilPozzer
@LilPozzer 2 жыл бұрын
@@Matlus Congratz! Really lots of work done!
@Zapanath
@Zapanath 4 жыл бұрын
Great video ! but i don't think the GC does reference counting like python does but rather it will build the object graph and determine which objects are rooted to / reachable by the application in memory.
@Matlus
@Matlus 4 жыл бұрын
Yes, you're correct in terms of the actual implementation. I was giving folks a conceptual model.
@Zapanath
@Zapanath 4 жыл бұрын
Shiv Kumar, ok i agree but excellent video anyway.
@Pablo0145
@Pablo0145 3 жыл бұрын
Thanks for the explanation, but what about constants, aren't they allocated in memory? as they are interpreted at compile time.
@Matlus
@Matlus 2 жыл бұрын
Check out my video on So you Think you know C#? Constants
@BhanuKer
@BhanuKer 3 жыл бұрын
@23:07 Static variables and members of classes that are value types are allocated inline or `in sitto`. I could not get the last word there that he said. What does he mean when he says in-sitto?
@Matlus
@Matlus 2 жыл бұрын
In Situ. It means in situation or in place.
@sachinucer
@sachinucer 2 жыл бұрын
why we have defined the Main Method inside the Stack .. does it mean static method will store in stack ? just wanted to clarify on this
@Matlus
@Matlus 2 жыл бұрын
Sorry, I don't understand your question. All methods get their own stack space when you call/execute a method. Method definitions are just definitions, they don't exist anywhere. However, just before being called, if they have not been JIT compiled before, then they will need to be compiled before they can be called and this compiled code also resides in memory (in the global heap and not stack)
@trongphan6197
@trongphan6197 6 жыл бұрын
Thanks again. @Shiv Do you have programming to exception? :)
@Matlus
@Matlus 6 жыл бұрын
Not yet. @Trong, but I hope to do this one soon.
@Matlus
@Matlus 4 жыл бұрын
Programming to Exceptions is now available Trong.
@DK-tr7ir
@DK-tr7ir 6 жыл бұрын
Looking forward for Part 2! :)
@trongphan6197
@trongphan6197 7 жыл бұрын
@Shiv Kumar I have a question. How under the hook the .Net Framework manage to know which value in the stack as value vs pointer? I might think it use a few bits to classify value type vs reference type? (20 vs 0x....) And how the MSIL really instruct to CPU to handle the value type vs reference type? Thanks,
@Matlus
@Matlus 7 жыл бұрын
All value types are derived implicitly from the System.ValueType. When a variable is declared using one of the basic, built-in data types or a user defined structure, it is a value type. An exception is the string data type, which is a reference type.
@trongphan6197
@trongphan6197 7 жыл бұрын
Thanks Shiv.
@trongphan6197
@trongphan6197 6 жыл бұрын
adamsitnik.com/Value-Types-vs-Reference-Types/ I found this article .... really good info
@Zapanath
@Zapanath 4 жыл бұрын
not to be pedantic but in the string immutability discussion, the string variable s1 was declared twice, that would be a compile error.
@Matlus
@Matlus 4 жыл бұрын
Dang it! PowerPoint has a bug :)
@filinskaya
@filinskaya 6 жыл бұрын
good content! Will part 2 be released?
@andreian4303
@andreian4303 6 жыл бұрын
Oh, Filinskaya? Is it you?
@Matlus
@Matlus 4 жыл бұрын
Hi @Marina, Part 2 is now available
@pramodkumarw
@pramodkumarw 4 жыл бұрын
Great Voice
@Matlus
@Matlus 4 жыл бұрын
Thank you Pramod! Did you enjoy the video?
@pramodkumarw
@pramodkumarw 4 жыл бұрын
@@Matlus i enjoyed this tutorial .you explained surgeon level memory management
@Matlus
@Matlus 4 жыл бұрын
@@pramodkumarw Thank you! Happy to hear that.
@JuankQuinteroMejia
@JuankQuinteroMejia 4 жыл бұрын
strings kind of behave like structs but they actually work as classes, that's important to know
@Matlus
@Matlus 4 жыл бұрын
You're correct. I'd say it slightly differently. Strings are reference types but behave somewhat like value types from the perspective of equality (value equality rather than reference equality). Additionally, when passing arguments to methods, once again they behave more like value types in that they behave like they are passed by value rather than by reference due to strings being immutable.
@adilk.1090
@adilk.1090 7 жыл бұрын
thanks that was very informative
@woozy_deer
@woozy_deer 6 жыл бұрын
This was so helpful!
@donchito6148
@donchito6148 6 жыл бұрын
great content
@PrraniilKkaddam
@PrraniilKkaddam 6 жыл бұрын
Hi... please provide for static class and variable memory management.
@Matlus
@Matlus 6 жыл бұрын
What do you mean by "variable memory management"?
@PrraniilKkaddam
@PrraniilKkaddam 6 жыл бұрын
Like if i have static class with static variable then How the memory is allocated internally and where? In depth C#
@Matlus
@Matlus 6 жыл бұрын
I explained this in the video. All static variable "hang off of" the static class, similar to how they are for objects. That is value types are in-line and reference types hold only the pointers in-line and they actual object is allocated elsewhere on the heap.
@PrraniilKkaddam
@PrraniilKkaddam 6 жыл бұрын
if you have online resource for the same then please refer i can study it.
@TheInsaneBrother
@TheInsaneBrother 5 жыл бұрын
Part two is here for everyone interested: kzbin.info/www/bejne/fZaTpayApsmbrrs
.Net Memory Allocations and Performance - Part 2
43:51
Shiv Kumar
Рет қаралды 4,6 М.
啊?就这么水灵灵的穿上了?
00:18
一航1
Рет қаралды 84 МЛН
This dad wins Halloween! 🎃💀
01:00
Justin Flom
Рет қаралды 22 МЛН
Where are types allocated in .NET and why people get it so wrong
14:35
Exploring NET's Memory Management - A Trip Down Memory Lane
59:12
Writing Allocation Free Code in C# - Matt Ellis
1:00:15
NDC Conferences
Рет қаралды 70 М.
.NET Stack and Heap
13:06
Wallace Kelly
Рет қаралды 103 М.
IDisposable Exposed
53:48
Shiv Kumar
Рет қаралды 3,3 М.
Turbocharged: Writing High-Performance C# and .NET Code - Steve Gordon
1:01:12
To LINQ Or Not To LINQ - That is the Question
32:35
Shiv Kumar
Рет қаралды 3,3 М.
Patterns for high-performance C# - Federico Andres Lois
1:08:55
NDC Conferences
Рет қаралды 53 М.
啊?就这么水灵灵的穿上了?
00:18
一航1
Рет қаралды 84 МЛН