Visual Stdio 2008 最大内存分配块大小问题: 使用new 分配连续723M内存 出错 std::bad_alloc at memory location 0x0013e0b8
|
|
I am using visual studio 2008 for developing. My program needs to deal with a huge amount of memory. The error happens when my program try to allocate a 512M float array. Code is the following:
Before this allocation, the program already consumed around 554M memory. My desktop has 4G main memory and I am using windows xp 32bits. How can I avoid the allocation error? Thanks very much for your input! |
||
|
feedback
|
Answer
|
Your array requires too much contiguous memory. Your program has a bit less of 2 gigabytes of virtual memory available but that address space is broken up by chunks of code, data and various heaps. Memory is allocated from the free space between those chunks. On a 32-bit operating system you can get ~650 MB when you allocate immediately. That goes South when your program starts using memory. The sum of all memory allocations is still ~2GB. Use a 64-bit operating system or partition your data structures. SysInternals' VMMap utility can give you insight in the virtual memory mapping of your program. |
|||||||
|

浙公网安备 33010602011771号
std::vector? – GMan Sep 13 '10 at 16:55int size = 512*1024*1024;. Also, I'd change the data type ofsizetosize_t. – Prætorian Sep 13 '10 at 17:24