views:

223

answers:

5

i´m doing a project using C, and CodeBlocks is my IDE. Windows Vista is the OS. I added some new stuff to the already working code and now the executable crashes everytime. i have no errors after compiling though. Computers and programming is not my field, but i suspect it may have something to do with some kind of memory limitations (if that exists and even makes sense). i say this because i´m working with three different 3D matrices/arrays of dimensions:

  • 1500x5x2
  • 1500x5x12
  • 1500x5x200

I then had another two 1D arrays both of dimension 1500. this was all working fine.

it started crashing when i added another three 2D matrices/arrays all of dimension 1500x5. if i comment some of the existing matrices, the new ones work fine, but only one at a time.

(btw, all the above referred matrices are of the INT type and were defined with pointers and callocs)

Any suggestions?

+5  A: 

There are limitations with platforms, etc, but your 3 3D matrices only use a few MB of RAM (just over 6), so I doubt that you're hitting the limits given those.

If it just started crashing when you added other matrices, I'd be more suspicious that you're having memory allocation/access errors on the pointers defining the new matrix code you added.

How are you defining your matrices?

---- EDIT ----

You should try to debug in CodeBlocks. This should tell you exactly where your crash is occurring.

Reed Copsey
matrix definitions:int *** layer=calloc(lines, sizeof(int **));for(i=0;i<lines;i++){ layer[i]=calloc(columns, sizeof(int*)); for(j=0;j<columns;j++) { layer[i][j]=calloc(hight, sizeof(int)); }}i dont exactly know how to "run it in a debugger" but will try and check this out.thanks
One thing, you don't need the *** - just use **. This will make it easier to manage. ** is a pointer to a pointer, but the second pointer can be a pointer to a pointer (since that's still just a reference to a memory location).
Reed Copsey
I added a link to debugging instructions for code blocks
Reed Copsey
AHAA !! thanks alot! i used the debugger and i found the problem. curiously enough, it had nothing to do with these matrices which only makes me wonder how it was working before!? Anyway, thanks alot for the help and i now know how to use the debugger :D
A: 

I'd suggest you learn how to use your IDE's debugger. We really don't have anything to go on yet.

Ken
+1  A: 

I wasn't aware that arrays could have negative dimensions.

In fact, I'm fairly certain they can't, as an array dimension is the number of items you plan on putting in it.

R. Bemrose
That's just a formatting issue. :::Fixes:::
Brian
A: 

Is there some kind of memory limit for an executable (written in C) to run without problems?

On a 32 bit OS your program is limited to 4GB of memory (less, actually, but that's the hard upper limit) because your pointer size is 32 bits, and you can only reference 4GB with a 32 bit pointer.

This shouldn't be the problem, though, as your biggest array only consumes less than 6MB - even if you instantiate a few hundred of these arrays you're ok.

You're pretty much following the standard way for creating dynamic multidimensional arrays in C:

int *** layer=calloc(lines, sizeof(int **));
for(i=0;i<lines;i++)
{ 
   layer[i]=calloc(columns, sizeof(int*));
   for(j=0;j<columns;j++) 
   { 
     layer[i][j]=calloc(hight, sizeof(int));
   }
}

So I'd look elsewhere in your code. Use the debugger. Make sure your array accesses aren't going out of bounds, or treating an array element as a pointer when it's not.

Adam Davis
A: 

Can you specify what kind of crash?

What message are you getting?

I quote an answer above:

"I'd suggest you learn how to use your IDE's debugger. We really don't have anything to go on yet."

Instead of guessing possible causes use the tools available to you to narrow down the problem to a specific line of code.

I have now seen in your comment that you have solved your problem but in general debugging properly is the only way to program and, when posting a problem provide as much code and details as possible!

Captain Lepton