堆栈主场迎战堆在.NET [英] Stack vs. Heap in .NET

查看:232
本文介绍了堆栈主场迎战堆在.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实际编程经验,你怎么堆和栈这方面的知识实际上是来救你在现实生活中?从战壕里的任何故事?或者是这个概念很好的填补了编程书籍和良好的理论?

In your actual programming experience, how did this knowledge of STACK and HEAP actually rescue you in real life? Any story from the trenches? Or is this concept good for filling up programming books and good for theory?

推荐答案

对我来说,是一个开发者/程序员和工匠之间的区别。任何人都可以学会写code和看到的东西只是神奇地出现你不知道为什么/如何。要真正成为你做什么有价值的,我觉得这是一个非常重要的,找出尽可能多地了解您所使用的框架。请记住它不只是一个的语言的,这是一个框架,你的杠杆作用创造最好的应用程序,以你的能力。

To me it is the difference between being a "developer/programmer" and a "craftsman". Anyone can learn to write code and see how things just "magically happen" for you not knowing why/how. To really be valuable at what you do, I think there is a great importance to find out as much as you can about the Framework you're using. Remember it's not just a language, it's a Framework that you leverage to create the best application to your abilities.

我已经分析了很多内存转储多年来,发现它非常有用的知道内部以及两者之间的差异。其中大部分已经出现内存不足的条件和不稳定的应用。当看到堆放这些知识是使用WinDbg绝对必要的。当调查内存转储,知道内存是如何分配的内核/用户模式进程之间和CLR至少可以告诉你在哪里开始你的分析。

I've analyzed many memory dumps over the years and found it extremely helpful knowing the internals and differences between the two. Most of these have been OutOfMemory conditions and unstable applications. This knowledge is absolutely necessary to use WinDbg when looking at dumps. When investigating a memory dump, knowing how memory is allocated between the kernel/user-mode process and the CLR can at least tell you where to begin your analysis.

例如,让我们的OOM情况: 分配的内存,你在堆大小看,工作集,专用内存,共享内存,虚拟内存,提交的内存,把手,和线程可以是从哪里开始一大指标。

For example, let's take an OOM case: The allocated memory you see in the Heap Sizes, Working Set, Private Memory, Shared Memory, Virtual Memory, Committed Memory, Handles, and Threads can be a big indicator of where to start.

目前,该CLR使用约8个不同的堆:

There about 8 different heaps that the CLR uses:

  1. 装载机堆:包含CLR结构和类型系统
  2. 高频堆:静,MethodTables,FieldDescs,接口映射
  3. 在低频堆:EEClass,类加载器和查找表
  4. 存根堆:存根中科院,COM包装,P / Invoke的
  5. 在大对象堆:需要超过85K字节的内存分配
  6. 在GC堆:用户分配的堆内存专用的应用程序
  7. 在JIT code堆:由mscoreee(执行引擎)分配的内存和JIT编译器管理code
  8. 工艺/基堆:互操作性/​​非托管的分配,本机内存,等等

查找什么堆具有高分配可以告诉我,如果我有记忆碎片,管理内存泄漏,互操作性/​​非托管泄漏等。

Finding what heap has high allocations can tell me if I have memory fragmentation, managed memory leaks, interop/unmanaged leaks, etc.

知道你有分配给每个线程的堆栈空间1MB,你的应用程序使用提醒我,如果我有100个线程,你将有虚拟内存使用额外的100MB。

Knowing that you have 1MB of stack space allocated for each thread that your app uses reminds me that if I have 100 threads you will have an additional 100MB of virtual memory usage.

我有一个客户端,有Citrix服务器崩溃与内存不足的问题,是当他们的应用程序是它在多个会话中运行不稳定,速度慢的响应。细算转储(我没有对服务器的访问),我看到有正在使用的应用程序的该实例超过700线程!了解线程的堆栈分配,让我来关联奥姆斯是由高线程使用造成的。

I had a client that had Citrix servers crashing with OutOfMemory problems, being unstable, slow responsiveness when their app was running on it in multiple sessions. After looking at the dump (I didn't have access to the server), I saw that there were over 700 threads being used by that instance of the app! Knowing the thread stack allocation, allowed me to correlate the OOMs were caused by the high thread usage.

在短的原因是什么我做我的角色,这是非常宝贵的知识有。当然,即使你没有调试内存转储它绝不会伤害无论是!

In short, because of what I do for my "role", it is invaluable knowledge to have. Of course even if you're not debugging memory dumps it never hurts either!

这篇关于堆栈主场迎战堆在.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆