Member Since: Aug 02, 2005
Mac Specs: 2.6GHz Core i7 15" MacBook Pro - 8GB DDR3 SDRAM - 750GB 7200 RPM HDD - GeForce 650M GT 1GB VRAM
11-07-2008, 10:57 PM
Originally Posted by skvikas
I am facing problem in dynamically allocating memory using c++. It fails with the following error msg.
main(14439) malloc: *** vm_allocate(size=235171840) failed (error code=3)
main(14439) malloc: *** error: can't allocate region
main(14439) malloc: *** set a breakpoint in szone_error to debug
terminate called after throwing an instance of 'std::bad_alloc'
My program at the time of crashing uses around 1.8GB of virtual memory. And i use gcc compile to compile.
This is mac pro machine with "Darwin" Operating System". This machine has 8GB of Physical memory and even at the time of failing it shows 3-4 GB of free physical memory and around 14GB of virtual memory. So i do not thing lack of memory is the problem.
The c++ compiler is a 64 bit compiler and it make a 64 bit executable. So memory address is also not a issue.
This machine do successfully run executable written in fortran (not by me) requiring 8GB of memory.
I tried to make a program just to allocate memory till the program crash because lack of memory space. And, this program crash at around 3.5 GB or 1.8 GB depending on the chunk of memory i am allocating at a given time. If i allocate 8KB at a time then it crash at 1.8 GB and if i allocate 8MB at a time than it takes around 3.5 GB before crashing out.
Please note here that for large chunk it goes further which i think is weired.
Also, I have much smaller linux machine on which my code runs fine but become too slow and take long time. But it does not go out of memory. So there does not seems to be any problem with code. Also i used memory leak tool to check that there is no memory leak.
I have no idea why this is happening and have no clue in which direction i should proceed. Please give me hint what could be possibly wrong.
If you could upload your code somewhere, that would be very helpful. Also describe what options you're using when you call g++ to compile your code. Additionally, what version of the GNU C Compiler are you using on Linux, and which version is in your OS X install?