c# - 开发和调试内存占用 C# 应用程序

标签 c# visual-studio wow64

我有一个 C# 应用程序,它必须与 32 位库链接并且还需要使用尽可能多的内存(成像应用程序);我们在 XP64 桌面上运行该应用程序,因此我们使用 WOW64,目标是在 Visual Studio for x86 中构建(并执行 editbin/largeaddressaware 构建后)。我们遇到了一些问题:

  • 在 Visual Studio 内置调试​​器中,我们只能使用 2gb 内存(应用约 1.5gb,加上开销)

  • 从命令行运行,应用程序可以看到 3gb 内存,但 Microsoft 文档似乎说我们应该看到 4gb。

谁能告诉我如何让 WOW64 C# 应用程序看到平台应该能够提供的完整 4gb?

此外,谁能告诉我如何让 Visual Studio(VS 2008,也称为 VS90)调试器遵守 /largeaddressaware 位并停止将应用程序内存限制为 2gb?

我在 VS80 和 VS90 中看到相同的行为; .NET Framework 3.5、3.0 和 2.0 之间也没有区别。这是一个简单的 C# 程序来说明问题;为 x86 构建,editbin/largeaddressaware,然后在内置调试器中运行与从命令行运行以查看 C# 可用内存的差异。

namespace MemoryAllocTest
{
class Program
{
    static void Main(string[] args)
    {
        const int allocSize = 1024 * 1024;
        List<byte[]> myMem = new List<byte[]>();
        UInt64 totalAlloc = 0;

        while (true)
        {
            myMem.Add(new byte[allocSize]);
            totalAlloc += allocSize;
            Console.WriteLine("{0} allocs: {1}MB total", 
             myMem.Count, totalAlloc / (1024 * 1024));
        }
    }
}
}

最佳答案

can anyone tell me how to get the Visual Studio (VS 2008, otherwise known as VS90) debugger to obey the /largeaddressaware bit and stop limiting the app memory to 2gb?

这需要两个步骤——都在项目属性中:

  • 在构建事件选项卡上,设置一个构建后步骤来运行 editbin /largeaware $(目标路径)
  • 在调试选项卡上,取消选中启用 Visual Studio 托管 过程

通过这两个步骤,您的示例程序运行到 3045MB

关于c# - 开发和调试内存占用 C# 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/803923/

相关文章:

c# - Visual Studio 调试显示 ‘Start’ 而不是浏览器

c# - AstBuilder 中的 ILSpy "Failed to resolve assembly"

C:打开();正在产生未处理的异常错误

c# - 在 Wow6432Node 中写入注册表值而不重定向

c# - 注册表项 EditionID 在 WOW6432Node 下有错误的值 - 是故意还是错误?如何绕过?

c# - SingleOrDefault,default怎么写出来?

c++ - 无法在 Visual Studio Community 2015 中编译基本程序(LNK2019 - MSVCRTD.lib)

visual-studio - 使用 Devenv.com 在命令行和输出日志文件中显示输出

windows - 为什么一些为 x86 编译的程序不能在 x64 下运行,而有些可以

javascript - Angular 和 ASP.NET MVC - 后端收到时参数为空