Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   Memory allocation fails (http://www.mac-forums.com/forums/os-x-development-darwin/129470-memory-allocation-fails.html)

skvikas 11-07-2008 02:51 PM

Memory allocation fails
 
Hi All,
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'
what(): St9bad_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.

Thanks,
Shailendra

Discerptor 11-07-2008 09:57 PM

Quote:

Originally Posted by skvikas (Post 753231)
Hi All,
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'
what(): St9bad_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.

Thanks,
Shailendra

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?


All times are GMT -4. The time now is 05:06 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.