![]() |
| | #1 |
| Registered User Join Date: Aug 2006
Posts: 61
| malloc error can't allocate region on mac os X Unexpectedly I am receiving a dynamic memory allocation error in my code when running on a Mac OS X (10.5), while that does not happen when I compile and execute the same code on a linux x86. the error is the following (one for each memory allocation call): ... testing.exe(13762) malloc: *** mmap(size=2132258816) failed (error code=12) *** error: can't allocate region ... and the lines of the code are wrapped below. Where could the problem be? I report my memory allocation lines here below thanks in advance S.M. The problem is the same either using malloc or calloc (with their respectively syntax) 1) option 1 with calloc: Code: _esup1 = (int*) calloc(1,sizeof(int)); _esup2 = (int*) calloc(nnodes+1,sizeof(int)); _nesup = (int*) calloc(nnodes+1,sizeof(int)); _lpoin = (int*) calloc(nnodes+1,sizeof(int)); _psup2 = (int*) calloc(nnodes+1,sizeof(int)); _npsup = (int*) calloc(nnodes+1,sizeof(int)); Code: _esup2 = (int*) malloc((nnodes+1)*sizeof(int)); _nesup = (int*) malloc((nnodes+1)*sizeof(int)); _lpoin = (int*) malloc((nnodes+1)*sizeof(int)); _psup2 = (int*) malloc((nnodes+1)*sizeof(int)); _npsup = (int*) malloc((nnodes+1)*sizeof(int)); |
| simone.marras is offline | |
| | #2 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| Are you sure nnodes is initialised? If you do this (and only this) in a new program, does it work? The problem is almost certainly down to some mis-use of some memory you've already allocated. Typically - accessing past the end of the memory you allocated - trying to free it twice - trying to free something never allocated.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #3 | |
| Registered User Join Date: Aug 2006
Posts: 61
| Quote:
Thank you very much S. | |
| simone.marras is offline | |
| | #4 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| You mis-understand. That it "works" on a single machine is basically down to luck as much as judgement. When you add new code, you have a chance of exposing previously hidden bugs. When you change your compiler flags (say a release or debug build), you have a chance of exposing previously hidden bugs. When you change compiler, you have a chance of exposing previously hidden bugs. When you change OS, you have a chance of exposing previously hidden bugs. And so it goes on. Debugging stops when the program works in a given environment, not when it's bug-free. > Anyhow, I think I can solve it by recoding it in a different way. I'm sure you can. But unless you understand why you're at the bottom of this particular hole, how will you know what to do to avoid finding yourself back in the same hole at some future time?
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #5 | |
| Registered User Join Date: Aug 2006
Posts: 61
| Quote:
I actually figured now that the problem originally was not in the function I sent, but in another one where the same malloc were being called. In there there there was a variable that was not being allocated beforehand ("sz"), and that is what caused it to crash. Now with sz properly allocated, all those malloc calls stop giving problems! thanks for helping and for the hint on good programming S. | |
| simone.marras is offline | |
| | #6 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| Excellent job
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #7 |
| Registered User Join Date: Aug 2006
Posts: 61
| Thanks! have a nice weekend s. |
| simone.marras is offline | |
![]() |
| Tags |
| calloc, error, malloc, region |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Playing mp3 files in Mac OS X | tek | C++ Programming | 23 | 08-30-2003 01:42 PM |
| Assembly & Mac OS X | kristy | Tech Board | 2 | 07-29-2003 04:29 PM |
| Mac Os X Vs Windows | hermit | A Brief History of Cprogramming.com | 25 | 09-07-2002 02:29 PM |
| download compilers for mac os? | Shadow12345 | C++ Programming | 1 | 06-06-2002 08:44 AM |
| compiled under windows, work for mac os? | Shadow12345 | C++ Programming | 1 | 05-09-2002 09:55 AM |