我有一个 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/