Thread: how number of two-dimensional array store ?

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    168

    how number of two-dimensional array store ?

    can I define as follows:
    Code:
       char a[785][106];
    for example , I define a two-dimensional array
    Code:
           char a[MAX1][MAX2];
    the MAX1 and MAX2 is how size?

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    You can do like this
    Code:
    #define MAX1 785
    #define MAX2 106
    char a[MAX1][MAX2];
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by BEN10 View Post
    You can do like this
    Code:
    #define MAX1 785
    #define MAX2 106
    char a[MAX1][MAX2];
    Can I assign MAX1 VARIABLE equal 100000000000?
    what is maxium value of MAX1 ?

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    That depends on your compiler and your hardware and operating system.

    Why don't you do a little experiment and see. When the array is too big, your compiler should give you an error to let you know that.

    Tell us what you can get. It will be large, but not *that* large!

  5. #5
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    The array will get stored in the stack, which is generally of 1-2MB, so depending on it, the memory occupied by the array should never overflow this much amount. So, you can't do what you are asking for, it'll result in stack overflow.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  6. #6
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by BEN10 View Post
    The array will get stored in the stack, which is generally of 1-2MB, so depending on it, the memory occupied by the array should never overflow this much amount. So, you can't do what you are asking for, it'll result in stack overflow.
    It'll be stored on the stack only if it is defined inside of a function.
    If it's outside of any function then it'll be stored in the data segment.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by zcrself View Post
    Can I assign MAX1 VARIABLE equal 100000000000?
    what is maxium value of MAX1 ?
    Hell no! Your computer wont have one hundred billion bytes of memory. And if your MAX2 is 106 as well then that's over ten-trillion bytes, which is probably well over your hard disk and RAM combined.

    Even an array that can only just fit in memory usually isn't practical. You don't pick array bounds at random anyway. You have to consider how big it actually needs to be, or whether an array is even the right thing to use anyway. A sparse multi-way trie could be an alternative.
    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
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by itCbitC View Post
    It'll be stored on the stack only if it is defined inside of a function.
    If it's outside of any function then it'll be stored in the data segment.
    Can you tell me if there's any restrinction on size of data segment just like there's on stack(1-2MB)?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by BEN10 View Post
    Can you tell me if there's any restrinction on size of data segment just like there's on stack(1-2MB)?
    Just use malloc to make you're two dimensional array, and try to make an educated guess how much memory you need to begin with. It's probably not billions of bytes. If your guess is not enough, you can use realloc to get more at any time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  2. two dimensional array
    By leisiminger in forum C Programming
    Replies: 12
    Last Post: 03-09-2008, 11:53 PM
  3. Two dimensional array
    By George2 in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 05:27 AM
  4. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  5. Using an Array to store the count.
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2001, 06:41 AM