.Net Memory Allocations and Performance

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ธ.ค. 2024

ความคิดเห็น • 120

  • @SatyendraRoutela
    @SatyendraRoutela 5 ปีที่แล้ว +6

    I generally don't comment on videos but your videos are really awesome.

    • @Matlus
      @Matlus  4 ปีที่แล้ว +2

      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

  • @himanshutyagi1205
    @himanshutyagi1205 4 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      So How was Part 2 Himanshu?

    • @himanshutyagi1205
      @himanshutyagi1205 4 ปีที่แล้ว +1

      @@Matlus Amazing. Kudos to you for the way you explain everything in details.

    • @Matlus
      @Matlus  4 ปีที่แล้ว +1

      @@himanshutyagi1205 Thank you! Appreciate the encouragement.

  • @amadzarak7746
    @amadzarak7746 2 หลายเดือนก่อน

    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

  • @dhanasekar4520
    @dhanasekar4520 3 ปีที่แล้ว +4

    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.

  • @DheerajKumarWebDetails
    @DheerajKumarWebDetails 4 ปีที่แล้ว +2

    You are just awesome , subscribed for life time

    • @Matlus
      @Matlus  4 ปีที่แล้ว +1

      Thank you Dheeraj!

  • @saurabhchauhan232
    @saurabhchauhan232 3 ปีที่แล้ว +1

    Excellent Presentation, Going to checkout part 2. 😀

    • @Matlus
      @Matlus  3 ปีที่แล้ว +1

      Thank you Saurabh! I'm positive you'll like part 2 as well.

    • @saurabhchauhan232
      @saurabhchauhan232 3 ปีที่แล้ว +1

      @@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.

  • @jaysonknight
    @jaysonknight 6 ปีที่แล้ว +8

    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.

  • @kurnaPunk
    @kurnaPunk 6 ปีที่แล้ว +12

    Fantastic video, part 2 pleeeeease!

    • @Matlus
      @Matlus  4 ปีที่แล้ว +2

      @Nicholas Zhang, Part 2 is out. Have you watched it?

  • @garethevans9789
    @garethevans9789 5 ปีที่แล้ว +3

    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 ปีที่แล้ว +2

      Hi Gareth, Part 2 is now available, please take a look

  • @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.

  • @09FT9
    @09FT9 4 ปีที่แล้ว +1

    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  4 ปีที่แล้ว

      Thank you for an inspiring and encouraging comment!

  • @davidpike5959
    @davidpike5959 4 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      @@Matlus Good man, i'm on it- thanks again :D

  • @charankumar5633
    @charankumar5633 2 ปีที่แล้ว

    I have been trying to understand properly on the memory allocation, finally I found one. Thanks for sharing this knowledge :)

  • @sarbanjeet
    @sarbanjeet ปีที่แล้ว

    Thank you so much, I never know the difference between static object and allocation before.

  • @kevinm8865
    @kevinm8865 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      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 ปีที่แล้ว +1

      @@Matlus So true! Thanks for the kind words and the education. New sub now!!

    • @Matlus
      @Matlus  3 ปีที่แล้ว +1

      @@kevinm8865 Thank you for subscribing Kevin!. By the way, there is a part 2 to this video I think you'll enjoy as well.

  • @dusanrychnovsky3837
    @dusanrychnovsky3837 5 ปีที่แล้ว +2

    Great video, Shiv, thanks! The part 2 you mentioned isn't available yet, is it? Thank you

    • @Matlus
      @Matlus  4 ปีที่แล้ว +1

      Hi
      Dušan, thank you! Yes, part 2 is now available.

  • @rakeshpathania829
    @rakeshpathania829 4 ปีที่แล้ว +1

    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. th-cam.com/video/Ge0tyJqdhxY/w-d-xo.html

  • @19gauravmittal91
    @19gauravmittal91 4 ปีที่แล้ว +1

    Amazing way of teaching with visualization. Please post about some latest tech like Micro-services.

  • @HumbertoPereira1994
    @HumbertoPereira1994 4 ปีที่แล้ว +1

    Fantastic Video!!!!!

    • @Matlus
      @Matlus  4 ปีที่แล้ว +1

      Thank you Humberto!

    • @Matlus
      @Matlus  4 ปีที่แล้ว +1

      Humberto, be sure to watch Part 2

  • @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  3 ปีที่แล้ว

      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.

  • @lalithswarna2097
    @lalithswarna2097 4 ปีที่แล้ว +1

    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.

  • @krishnanigalye1173
    @krishnanigalye1173 4 ปีที่แล้ว +1

    Thank you for this video. Great in-depth explanation. Even before watching half of this video, I subscribed to your channel.

    • @Matlus
      @Matlus  4 ปีที่แล้ว +1

      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!

  • @BobbyCannon
    @BobbyCannon 4 ปีที่แล้ว +8

    "Hello Viewers" (bass, bass, all about that bass) - I was like woah...

    • @Matlus
      @Matlus  4 ปีที่แล้ว +1

      Be sure to watch Part 2 of this one too Bobby

    • @LaurentLaborde
      @LaurentLaborde 4 ปีที่แล้ว +2

      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 ปีที่แล้ว +1

    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.

  • @techypd559
    @techypd559 4 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      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.

  • @Sushilkumar-yq7iy
    @Sushilkumar-yq7iy 4 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      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 :)

  • @bigbtripathi
    @bigbtripathi 4 หลายเดือนก่อน

    Superb information. From where did you get this information ? Is it published by microsoft? Does the latest .net core framework uses the same principle ?

  • @benjaminb.4043
    @benjaminb.4043 6 ปีที่แล้ว +1

    @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 ปีที่แล้ว +1

      @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

  • @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 ปีที่แล้ว +1

      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.

  • @conchimxanhxanh255
    @conchimxanhxanh255 4 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

      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 4 ปีที่แล้ว

      www.pdfdrive.com/writing-high-performance-net-code-e195138098.html

  • @brianmikinski8984
    @brianmikinski8984 6 ปีที่แล้ว +1

    This is great. Can't wait for part 2.

    • @Matlus
      @Matlus  4 ปีที่แล้ว

      Hi Brian, part 2 is now available

  • @LilPozzer
    @LilPozzer 3 ปีที่แล้ว +1

    Hope you'll get more than 10k subs!

    • @Matlus
      @Matlus  3 ปีที่แล้ว

      I hope so too. Very close now!

    • @LilPozzer
      @LilPozzer 3 ปีที่แล้ว

      @@Matlus Congratz! Really lots of work done!

  • @DevNerdKonradKokosa
    @DevNerdKonradKokosa 3 ปีที่แล้ว +1

    If you find those topics interesting, feel free to watch my in-depth .NET GC Internals series at th-cam.com/play/PLpUkQYy-K8Y-wYcDgDXKhfs6OT8fFQtVm.html 👀

    • @Matlus
      @Matlus  2 ปีที่แล้ว

      Thank you Konrad! You have great content indeed!

  • @Trhnetesiuz
    @Trhnetesiuz 3 ปีที่แล้ว +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 ปีที่แล้ว +1

      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.

  • @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.

  • @JonatanMachado
    @JonatanMachado 5 ปีที่แล้ว

    Great Video!
    Looking forward to part 2.

  • @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)

  • @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  3 ปีที่แล้ว

      Check out my video on So you Think you know C#? Constants

  • @filinskaya
    @filinskaya 6 ปีที่แล้ว +1

    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

  • @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 ปีที่แล้ว +1

      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

  • @pramodkumarw
    @pramodkumarw 4 ปีที่แล้ว +1

    Great Voice

    • @Matlus
      @Matlus  4 ปีที่แล้ว +1

      Thank you Pramod! Did you enjoy the video?

    • @pramodkumarw
      @pramodkumarw 4 ปีที่แล้ว +1

      @@Matlus i enjoyed this tutorial .you explained surgeon level memory management

    • @Matlus
      @Matlus  4 ปีที่แล้ว +1

      @@pramodkumarw Thank you! Happy to hear that.

  • @trongphan6197
    @trongphan6197 6 ปีที่แล้ว +1

    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.

  • @EminoMeneko
    @EminoMeneko 3 ปีที่แล้ว +1

    Thank you for the video.

    • @Matlus
      @Matlus  3 ปีที่แล้ว

      Thank you! And you're most welcome.

  • @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 ปีที่แล้ว +1

      Dang it! PowerPoint has a bug :)

  • @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 ปีที่แล้ว +1

      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.

  • @donchito6148
    @donchito6148 7 ปีที่แล้ว

    great content

  • @JuankQuinteroMejia
    @JuankQuinteroMejia 4 ปีที่แล้ว +1

    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.

  • @woozy_deer
    @woozy_deer 6 ปีที่แล้ว

    This was so helpful!

  • @adilk.1090
    @adilk.1090 7 ปีที่แล้ว

    thanks that was very informative

  • @TheInsaneBrother
    @TheInsaneBrother 5 ปีที่แล้ว

    Part two is here for everyone interested: th-cam.com/video/Ge0tyJqdhxY/w-d-xo.html