tags:

views:

98

answers:

4

The Memory that i'm trying to allocate is not huge or any thing. 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?

+2  A: 

Take a look at this article Overcoming the Windows 2GB Caching Limit

Flesrouy
+1  A: 

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.

Ira Baxter
well, you got that right ... and i just tried the same thing with delphi 2009 and i was able to allocate the 1.5 gigabytes but not one megabyte more
yosef
+3  A: 

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.

psmears
thanks .. but i can't even allocate less than 2G ... even 1.2 gigabytes fails
yosef
@yosef: That 2GB has to contain all of your program, all of the other data it uses, all of its DLLs, all of the DLLs' data, etc etc. So if you can't allocate 1.2GB, it's possible that it's already using ~800MB. Another possibility is that the memory is fragmented. In either case, using the 4GB tuning techniques mentioned in the answer may help.
psmears
A: 

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.

KenE
no.. i just started an empty project and i just write void* ptr = malloc(1500*1024*1024); actually when i tried that the max i could get is 1.6 gigabytes......but with a normal application i can't even get 1.2i think it's memory fragmentation. which is wierd too because the application is taking 50 megabytes at best before the call to malloc
yosef