Is there a limitation for allocating memory on the heap?
build is a 64bit exe
OS is WIN7 64.
physical memory is 12GB
Trying to get a chunk of memory larger than 2 GB always
returns an error.
Probably this is your process maximum allocatable heap size.
Try to run Sysinternals TestLimit64.exe.tool and observe how much memory it was able to allocate.
This book can be also helpful: http://technet.microsoft.com/en-us/sysinternals/bb963901.aspx
Can you show the statement that fails.
int _tmain(int argc, _TCHAR* argv)
double* array = NULL;
__int64 N = 1000000000ll; // 8GB
array = new double[N];
The above works (on my Win7 system) provided: a) 64-bit build, b) page file is large enough
Theoretical limit of virtual memory process address space on Windows 64bit is 8TB.
>>Theoretical limit of virtual memory process address space on Windows 64bit is 8TB.
At issue is not the Virtual Address space. What is at issue here is mapping the allocation to the page file. On Windows you can fix the page file size and/or limit expansion and/or have a space limitation on the drive(s) selecting for the page file. The heap, when insufficient memory is in the current heap, will request a blob of Virtual Memory be mapped to the page file (it may or may not do other things like wipe). This assigns (maps) portions of the process Virtual Memory to page file pages. If necessary, and permitted, and if sufficient disk space is available, the page file is expanded. If the expansion cannot fulfill the request, you get an error.
Thanks for the explanation.
As a side note. Other O/Ss may implement a lazy page file mapping/expansion. What happens here is an overly large allocation will succeed (non NULL pointer returned), however, during use later, eventually you get a page fault when the page file cannot be extended. IMO the error should occur on the allocation not on the use.
Additional note. Although the Virtual Memory to Page File mapping (reservation) is performed on allocation, it need not be associated with physical RAM until first touch. IOW on NUMA system the physical memory mapping occurs on first touch.