Thread: 2 dimensional array

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    197

    2 dimensional array

    Code:
    # define maxnodes 20000
    and when i define long long int a[maxnodes][maxnodes] i get size of a is too large ...(compile error)...
    is there any way to solve this

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, 20000 x 20000 is 381M entries, times 8 makes it about 3 GB, which is more than what a user-mode application in windows can do.

    You probably will need to use a sparse matrix or some such.

    More later - got a train to catch.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    197

    Smile

    yes i know....
    well am asking any other stl will solve this issue?

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    197
    i know map can solve single dimensional thing...but here it is 2 -d... i need 2 keys to map to a value....
    any other approach plz

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Allocate on the heap using new, or make a vector of vectors.

  6. #6
    Registered User
    Join Date
    Jan 2009
    Posts
    197
    can u explain me in detail tabstop... will be helpful with the syntax

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by tabstop View Post
    Allocate on the heap using new, or make a vector of vectors.
    That wont stop him from trying to use about 3GB on a 32-bit machine and failing.

    dpp: Your only option is to explain in enough detail exactly what you plan on storing in this 2D array, and what the whole thing is for. Also comment on whether you need to store a value in every 'cell' of this 2D array.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The obviously easy solution is to go out and buy a machine with about 6GB of RAM, and install a 64-bit OS.

    Beyond that, the other solution is a sparse matrix, but that ONLY works if there are large gaps in the matrix. With no gaps, then you have no option.

    Obviously, if you could use long instead of long long, that would halve the size, and it may fit within the limits.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    197

    Wink

    well the scenario is i scan a few i/ps n number of times
    Code:
    while(x>5)
    {
    cin>>a>>b;
    array[a][b]=1
    }
    not all the positions will be valued in the array...
    a and b can be atmost the value i specified in the first post

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, if you only ever store a one in the position, why do you need to have unsigned long long array? A char or bool array would work just as well, and take up much less space.

    Sorry, but if you are not telling us the whole story, we can only help you with the bits you tell us, so if array[a][b] = 1 is not what ACTUALLY goes on, then that's obviously changing the above advice.

    The other option is of course to not do this using an array at all, but by simply storing the a & b values somehow.

    How you solve this will very much depend on what you are actually trying to achieve in overall terms.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Registered User
    Join Date
    Dec 2008
    Posts
    65
    Do you need all of the data in memory at one time? If not make a stream buffer for cin, do your logic test and then throw away the data.
    Last edited by Phyxashun; 03-03-2009 at 01:44 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. two dimensional array
    By leisiminger in forum C Programming
    Replies: 12
    Last Post: 03-09-2008, 11:53 PM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  4. Replies: 5
    Last Post: 11-20-2001, 12:48 PM