开发者

How can i allocate a 2 gigabyte chunk of memory in c++?

开发者 https://www.devze.com 2023-01-07 21:05 出处:网络
The Memory that i\'m trying to allocate is not huge or any thin开发者_运维百科g. i just cant allocate

The Memory that i'm trying to allocate is not huge or any thin开发者_运维百科g. i just cant allocate 1.5 to 1.7 gigabyte of contagious memory. From what i know, windows gives you 2 gigabytes of virtual space to use in your application. so, a call like malloc(1500*1024*1024) is not totally crazy. i tried malloc ,new[], VirtualAlloc all didn't work.

is there something i'm missing here? someone told me it has something to do with physical memory, i totally dismissed that because why was virtual space ,address translation tables and TLBs invented if i'm allocating physical memory.

if i'm allocating a 1.5 gig on a machine with 256 megabytes of ram and i try to access shouldn't the system be thrashing but working?


Different versions of Windows have different memory restrictions. If you're using a 32-bit version, you may need to use the 4GB tuning techniques to allocate more than 2GB.


If you are running a 32 bit version of windows, you have a max of 2Gb of virtual space. Your compiled programs and the C/C++ runtime libraries each use up some part of it, along with preallocated code and data segments. If you run a 32 bit windows, you have less memory space than you think. I'll agree that 1.5 Gb doesn't sound unreasonable, but then you would think that MS products weren't unreasonable, too, right?

Try samller pieces as a sanity check, (e.g., 1Gb); I suspect that will succeed. And try big allocations on a 64 bit system, where there isn't any practical upper limit.


Are you using ODBC? The ODBC dlls in 32-bit windows seem to insert themselves at an awkward place in the virtual address space, causing large allocations like yours to fail. A workaround is to configure your app to delay load the ODBC dlls, and then make sure you allocate your big chunk before you call anything that uses ODBC.

0

精彩评论

暂无评论...
验证码 换一张
取 消