Passing big multi-dimensional array to function in C
Posted
by kirbuchi
on Stack Overflow
See other posts from Stack Overflow
or by kirbuchi
Published on 2010-05-27T22:42:17Z
Indexed on
2010/05/27
22:51 UTC
Read the original article
Hit count: 347
Hi, I'm having trouble passing a big array to a function in C.
I declare:
int image[height][width][3]={};
where height and width can be as big as 1500. And when I call:
foo((void *)image,height,width);
which is declared as follows:
int *foo(const int *inputImage, int h, int w);
I get segmentation fault error. What's strange is that if my values are:
height=1200;
width=290;
theres no problem, but when they're:
height=1200;
width=291;
i get the mentioned error. At 4 bytes per integer with both height and width of 1500 (absolute worst case) the array size would be of 27MB which imo isn't that big and shouldn't really matter because I'm only passing a pointer to the first element of the array. Any advice?
© Stack Overflow or respective owner