“你好,世界!"在.NET 4中生成3500页错误 [英] "Hello, World!!" in .NET 4 generates 3500 page faults

查看:41
本文介绍了“你好,世界!"在.NET 4中生成3500页错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.NET 4运行Windows Vista和Visual Studio 2010.2 GB的RAM和大约800 MB的免费空间.

I'm running Windows Vista and Visual Studio 2010, using .NET 4. 2 GB of RAM and about 800 MB free.

我创建Windows窗体应用程序,并且不向其添加任何代码.只需在发布模式下进行编译,关闭Visual Studio并启动应用程序即可.如果我在任务管理器中查看,该应用程序仅启动就什么也不做,就产生了3500页错误.

I create a Windows Form application and add no code to it. Just compile it in release mode, close Visual Studio and start the application. If I look in task manager the application generated 3500 page faults for just starting and doing nothing.

如果我创建控制台应用程序并仅添加 Console.ReadLine(); 使其保持打开状态,则会产生1500页错误.

If I create a console application and just add a Console.ReadLine(); to keep it open it generates 1500 page faults.

.NET是正常行为吗?这些数字对我来说简直太荒谬了.

Is that normal behaviour for .NET? These numbers seem ridiculously high to me.

推荐答案

您必须了解,.NET应用程序中包含的代码不仅仅是您编写的代码.它必须加载程序集,对其进行解析,编译,执行,然后加载到各种支持库中,等等.(其中一些可能需要类似的解析,编译等.),所有这些都会造成页面错误.在宏伟的计划中,没有3500个页面错误.

You have to understand that there's more code to a .NET application than just the code you wrote. It has to load the assembly, parse it, compile it, execute it, then load in various support libraries, etc.. (some of which may require similar parsing, compiling, etc..), and all of those things create page faults. 3,500 is not that many page faults in the grand scheme of things.

作为示例,我尝试了一些简单"的控制台应用程序.更多操作是从控制台运行的,会产生750个页面错误,这是一个很小的应用程序,除了执行从一个输入到另一个输入的回声外,其他功能不多.它是用C语言编写的,不是垃圾收集的语言,没有虚拟机,或者必须附带一个大型运行时库(它是静态链接的,因此不依赖于运行时).

As an example, I tried out a few "simple" console applications. More, run from a console, generates 750 page faults, and this is a pretty tiny application that does little more than echo from one input to the other. It's written in C, a language that is not garbage collected, doesn't have a virtual machine, or a big runtime library that has to come with it (it's statically linked, so it's not depending on a runtime).

鉴于.NET所做的一切,一个仅使用1,500页错误即可执行ReadLine的单行控制台应用程序似乎非常不错.

Given all that .NET does, a single line console application that just does a ReadLine using only 1,500 page faults seems quite good.

我什至不知道您为什么关心页面错误.也许您来自页面错误是一件坏事的平台.在Windows中,进程是支持页面的",这意味着OS内存会映射可执行文件,然后根据需要加载页面(这包括共享库以及可执行文件本身,图标,图像,各种东西).当操作系统需要将这些页面加载到内存中时,这些页面中的每个页面都会产生页面错误.那是正常的,这就是操作系统的工作方式.

I'm not even sure why you care about page faults. Perhaps you are coming from a platform where page faults are a bad thing. In Windows, processes are "page backed", which means that the OS memory maps an executable, and then demand loads pages as needed (this includes shared libraries, as well as the executable itself, icons, images, all kinds of things). Each of those pages generate a page fault when the OS needs to load them into memory. That's normal, and that's the way the OS works.

这篇关于“你好,世界!"在.NET 4中生成3500页错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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