Matrix limit?
Hi everybody,
I am writting a C++ code in Xcode and I got an error while compiling. Let me talk about my code: I am working with a 3D matrix that I defined with the command
double array [X][Y][Z];
This array is a 150x20x820 matrix (which doesn't seem too much for me...) and when I compile my code I got the following error message :
Program received signal: “EXC_BAD_ACCESS”.
sharedlibrary apply-load-rules all
warning: Unable to restore previously selected frame.
No memory available to program now: unsafe to call malloc
Data Formatters temporarily unavailable, will re-try after a 'continue'. (The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (dlopen) will be abandoned.)
kill
quit
I have to admit that this message is quiet unclear for me, and I read that it can happen for almost any mac applications, so I don't know what to think about it...
I tried to reduce the size of my matrix to 150*7*820 and the code compiled perfectly and almost instantaneously!! Did I reach the limit size of the matrix? (by the way, what is that limit?)
I'd rather thought about the limit of the allocated memory or something like that. So I used the defaults command to limit the number of parallel tasks to 2 using PBXNumberOfParallelBuildSubtasks and to increase the system cache size to 3072 using BuildSystemCacheSizeInMegabytes but it didn't change anything!! (although I am not sure I did it well...)
Another method might be to change the "type" of the matrix I used, but I don't know any other else! (Well I do but I can't make the Meschach's, Cooperware's or Blitz's libraries work!) Is there something similar to but for matrices? Talking about vectors, what is the point of using it instead of an 1D array (except the fact that a vector size could be defined with double and not only integer)?
Thank you for your help!!




Stacksize limit
Hello,
You probably hit the stacksize limit, because you aren't allocating memory for the array dynamically -- rather it is going on the stack. This would explain why it works for smaller arrays.
If you type "limit" in a terminal window you'll see the stacksize limit. You can then increase the size of the stacksize by typing "limit stacksize unlimited" -- which will increase the stacksize up to a maximum (but not unlimited) size. A better way to deal with this is to allocate the array dynamically, using "new" or "malloc" or "calloc". Then you can make use of all of the available memory.
more information needed ...
I assume you don't get the error while compiling, but when running the code. If you have compiled your application using the Debug configuration, the debugger should actually tell you in which line it crashed. EXC_BAD_ACCESS can be caused by many things, and without more information on your code it is impossible to tell what caused it.
Can you reduce your code to something small that still crashes and post the code here?
As for the limit: I think if you declare your matrix as a fixed-size array (like "double [150][20][180]") it will be located on the stack (I could be wrong here - any memory allocation experts around here?). The stack size is indeed limited, in bash you can find out your stack size limit with "ulimit -s". If you are dealing with larger matrices, you should really use dynamic memory allocation (which allocates the memory on the heap, not on the stack).
coincidence ...
*lol* Brad, we must have hit the enter key almost simultanously :)