Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Memory allocation and virtual memory

aurora_s
Beginner
486 Views
Hi,
I have a question about memory reservation. If I run my test application main.cpp in 32 bits11.1.070 [IA-32], the output its an out of memory in the moment that I ask for more memory than 2gb.
In 64 bits (same compiler version), the SO starts to allocate memory and when it reaches the maximum of my computer (8gb), it gets hanged competely when paging (I suppose).
How can I achieve to return an "out of memory" error instead of using unlimited virtual memory and hang my computer?
Thanks in advance!
main.cpp
0 Kudos
5 Replies
JenniferJ
Moderator
486 Views
is this on Linux? we tried on Windows, it works as expected.

please post your compile and link options as well.

thanks,
Jennifer
0 Kudos
Alexander_W_Intel
486 Views

Hi,

at the moment the memory limit of a 64 bit process is out of reach. So you will not get an out of memory exception until all the virtual memory is used completely. Normally the OS starts paging if the physical memory is short and the system behaves really slow.

If you want to avoid that, you have several options. One would be to query the OS about the free physical memory. Check if the amount is below a certain threshold and then throw an out of memory exception.
To check the memory you can use the following APIs:
Windows*: http://msdn.microsoft.com/en-us/library/aa366589%28VS.85%29.aspx
Linux: Read /proc/meminfo

Thanks,
Alex

0 Kudos
aurora_s
Beginner
486 Views
Which are the other options?
I've reproduced that it in Win7 64 bits with the default release/debug options of visual studio 2008.
This issue is being investigated in the premier support (issue number638135) since July, but now I want to know if are there any alternatives
Thanks!
0 Kudos
Om_S_Intel
Employee
486 Views
I tried your test case. It works as expected in Windows7 64 bit version, Intel 64, using VS2010 and icl 12.0.

c:\forum\U84518>icl /EHsc maincpp.cpp

Intel C++ Intel 64 Compiler XE for applications running on Intel 64, Ve

rsion 12.0.5.221 Build 20110719

Copyright (C) 1985-2011 Intel Corporation. All rights reserved.

maincpp.cpp

Microsoft Incremental Linker Version 10.00.40219.01

Copyright (C) Microsoft Corporation. All rights reserved.

-out:maincpp.exe

maincpp.obj

c:\forum\U84518>maincpp.exe

Out of memory with i=25742.... 1627Mb/37636Mb

Press any key to continue . . .

0 Kudos
aurora_s
Beginner
486 Views
So its a bug solved in version 12? I use11.1.070 64 bits
0 Kudos
Reply