Array size in C

This is a discussion on Array size in C within the C Programming forums, part of the General Programming Boards category; I'm trying to declare a 2-dimensional array in C of length 40000. int matrix[40000][40000]; but the compiler is telling me ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    17

    Array size in C

    I'm trying to declare a 2-dimensional array in C of length 40000.

    int matrix[40000][40000];

    but the compiler is telling me that the size of variable 'matrix' is too large. I'm using gcc and have a couple of hundred Megs of RAM on my PC.

    Anyone got any ideas?

    Thanx,

    ROb.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    > int matrix[40000][40000];
    40000 * 40000 * 4 = 6.4GB
    No where near enough RAM (or address space for that matter)

    Time for plan B

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeah, as Salem said (but didn't expand), you have declared to have 40000 * 40000 amount. What you want to do is:

    int matrix[200][200];

    Try this and tell me your result.

    --Garfield
    1978 Silver Anniversary Corvette

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    17
    Tried that Garfield, thing is though i've got a data file in the form of

    1 2 768
    1 3 398
    1 4 398.67

    and there is 47306 lines like this because its the value of 218 cities distance from each other so 218*217 lines of info. I'm wondering how if anyway i can represent this in the program so that the program can retrieve the distance between cities x and y whenever it wants.

    Thanx for your reply,

    Rob.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    > and there is 47306 lines like this because its the value of 218 cities
    So that's going to be
    double distances[218][218];

    > 1 2 768
    > 1 3 398
    > 1 4 398.67
    First pair are 'from' and 'to' right?

    So logically you have
    distances[from][to] = 768;

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    17

    Thumbs up

    Gift Salem,

    I don't know what i was thinking with 40000 and other crazy high numbers. Thanks for bringing me back down to earth, my head was in the clouds.

    Nice one,
    Thanx,

    Rob.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. size of array
    By goran00 in forum C Programming
    Replies: 38
    Last Post: 04-02-2008, 10:57 AM
  2. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  3. Replies: 42
    Last Post: 12-19-2004, 08:59 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21