structure size !!

Discussion in 'C' started by Jatsui, Oct 17, 2008.

  1. Jatsui

    Jatsui New Member

    Joined:
    Feb 1, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    London, UK
    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.
     
  2. Jatsui

    Jatsui New Member

    Joined:
    Feb 1, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    London, UK
    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...
     
  3. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    More detail would be useful. Could you show us the struct?
     
  4. Jatsui

    Jatsui New Member

    Joined:
    Feb 1, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    London, UK
    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..

    Thanks in advance again.
     
  5. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    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.
     
  6. Jatsui

    Jatsui New Member

    Joined:
    Feb 1, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    London, UK
    All understood.

    Appreciate it, thanks for the help.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice