你应该分配多少内存? [英] How much memory should you be able to allocate?

查看:118
本文介绍了你应该分配多少内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我正在编写一个使用大量地理数据的C ++程序,并希望加载大块来一次处理。我不得不使用为32位机器编译的应用程序。我正在测试的机器是运行一个64位操作系统(Windows 7)和6千兆RAM。使用MS VS 2008。

Background: I am writing a C++ program working with large amounts of geodata, and wish to load large chunks to process at a single go. I am constrained to working with an app compiled for 32 bit machines. The machine I am testing on is running a 64 bit OS (Windows 7) and has 6 gig of ram. Using MS VS 2008.

我有以下代码:

byte* pTempBuffer2[3];
try
{
	//size_t nBufSize = nBandBytes*m_nBandCount;
	pTempBuffer2[0] = new byte[nBandBytes];
	pTempBuffer2[1] = new byte[nBandBytes];
	pTempBuffer2[2] = new byte[nBandBytes];
}
catch (std::bad_alloc)
{
	// If we didn't get the memory just don't buffer and we will get data one
	// piece at a time.
	return;
}



我希望我能够分配内存,直到应用程序到达4位字节限制的32位寻址。但是,当nBandBytes为466,560,000时,新的throws std :: bad_alloc在第二次尝试。在这个阶段,进程的工作集(内存)值是665,232 K所以,我似乎不能得到一个gig的内存分配。

I was hoping that I would be able to allocate memory until the app reached the 4 gigabyte limit of 32 bit addressing. However, when nBandBytes is 466,560,000 the new throws std::bad_alloc on the second try. At this stage, the working set (memory) value for the process is 665,232 K So, it I don't seem to be able to get even a gig of memory allocated.

有一些提到在32位Windows中的应用的2 gig限制,可以扩展到3 gig与/ 3GB开关为win32。这是在这种环境下的好建议,但与这种情况不相关。

There has been some mention of a 2 gig limit for applications in 32 bit Windows which may be extended to 3 gig with the /3GB switch for win32. This is good advice under that environment, but not relevant to this case.

在64位操作系统下,使用32位应用程序应该分配多少内存?

How much memory should you be able to allocate under the 64 bit OS with a 32 bit application?

推荐答案

与操作系统想要的一样。默认情况下,Windows允许32位进程具有2GB的地址空间。这被分成几个块。为堆栈留出一个区域,其他每个可执行文件和加载的dll。任何剩下的都可以动态分配,但不能保证它将是一个大的连续块。

As much as the OS wants to give you. By default, Windows lets a 32-bit process have 2GB of address space. And this is split into several chunks. One area is set aside for the stack, others for each executable and dll that is loaded. Whatever is left can be dynamically allocated, but there's no guarantee that it'll be one big contiguous chunk. It might be several smaller chunks of a couple of hundred MB each.

如果使用LargeAddressAware标志编译,64位Windows将允许您使用完整的4GB地址空间,这应该有点帮助,但一般来说,

If you compile with the LargeAddressAware flag, 64-bit Windows will let you use the full 4GB address space, which should help a bit, but in general,


  • 你不应该假设可用的内存是连续的。您应该能够使用多个较小的分配,而不是几个较大的分配,

  • 如果您需要大量内存,则应将其编译为64位应用程序。

这篇关于你应该分配多少内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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