Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   structure size !! (http://www.go4expert.com/forums/structure-size-t14601/)

 Jatsui 17Oct2008 19:42

structure size !!

Hi,

I have a 2D struct with one of the dimensions having about half a million array elements. It gives me the following error:

"relocation truncated to fit..."

Was wondering how I can fix this problem. I have been looking for a solution, but nothing yet.
I think it is to do with increasing the struct size, if I am right with this, how do I go about doing this ??

Many thanks.

 Jatsui 17Oct2008 19:48

Re: structure size !!

Ok guys, there is something else...

when I have 500,000 elements, it give me the error mentioned above.
So when I tried reducing the size (no. of elements) to find a sort of a threshold, I noticed that with a size of 411,000, it still gives me the error but with 410,000 elements, it NO LONGER gives me the error.

Q1) Any idea why 410,000 or have any of you experienced this before ?

Q2) I have to include about 500,000, so what can be the solution to this ?

Thanks again...

 oogabooga 17Oct2008 22:07

Re: structure size !!

More detail would be useful. Could you show us the struct?

 Jatsui 19Oct2008 04:23

Re: structure size !!

For eg., the declaration in the 'C', which is what I am using would look something like:

-----------------------------------------------------------
typedef struct {
int a,b;
}
vector c[100][500000];
-------------------------------------------------------------

so as mentioned in my previous post,
vector c[100][410000] - works fine
vector c[100][411000] - does NOT work fine

Now, i do understand that this may be due to high no. of elements, but is there a solution to this other than the simple one of using smaller struct size..

 oogabooga 19Oct2008 05:29

Re: structure size !!

I'm assuming C (although it does not have "vectors"!).
This does not work:
Code:

```#include <stdio.h> typedef struct MyStruct {     int a, b; } MyStruct; int main() {     MyStruct c[100][500000];     c[0][0].a = 1;     printf("a: %d\n", c[0][0].a);     return 0; }```
This does:
Code:

```#include <stdio.h> typedef struct MyStruct {     int a, b; } MyStruct; MyStruct c[100][500000]; int main() {     c[0][0].a = 1;     printf("a: %d\n", c[0][0].a);     return 0; }```
So it is a matter of running out of stack space.
Your 400MB array needs to be declared globally (on the "heap"),
or you have to drastically increase your stack space.
I'd recommend declaring it globally.

 Jatsui 21Oct2008 00:00

Re: structure size !!

All understood.

Appreciate it, thanks for the help.

 All times are GMT +5.5. The time now is 22:32.