array too large?

Discussion in 'C++' started by Developwebsites, Dec 18, 2003.

  1. const int MAX=999;

    class person {
    protected:
    char firstname[MAX][MAX],
    lastname[MAX][MAX];
    int ID[MAX];

    public:
    person();
    };

    I get an array size too large error.
    Is 999x999 array too large or is a single 999 array too large?

    --------------------------------------------------
    *** E-mail is shut off ***
    --------------------------------------------------
     
    Developwebsites, Dec 18, 2003
    #1
    1. Advertising

  2. Hi!

    Developwebsites wrote:
    > const int MAX=999;
    >
    > class person {
    > protected:
    > char firstname[MAX][MAX],
    > lastname[MAX][MAX];


    Why do you need such a big 2 dimensional array for
    firstname? Looks weird to me.

    > int ID[MAX];
    >
    > public:
    > person();
    > };
    >
    > I get an array size too large error.
    > Is 999x999 array too large or is a single 999 array too large?


    Most Compilers set a limit to the size of arrays on the
    stack. About 1 Million byte is probably too much...

    Your class design looks very weird to me. I think you are
    wasting a lot of memory.

    So: Dont use a buildin array, use std::vector!

    class person {
    protected:
    vector<string> firstname;
    vector<string> lastname;
    vector <int> ID;

    public:
    person();
    };

    Im not quite sure why a person should have more then one
    lastname, but maybe I misunderstand your intention.

    Or maybe you want to create an array of several persons.
    In this case I would do it about this way:

    class Person {
    std::string firstname;
    std::string firstname;
    int id;
    public:
    // Some methods here

    };

    class Persons {
    vector<Person> persons;
    // Some methods here
    };

    hth,

    Christoph
     
    Christoph Rabel, Dec 18, 2003
    #2
    1. Advertising

  3. Developwebsites wrote:

    > const int MAX=999;
    >
    > class person {
    > protected:
    > char firstname[MAX][MAX],
    > lastname[MAX][MAX];
    > int ID[MAX];
    >
    > public:
    > person();
    > };
    >
    > I get an array size too large error.
    > Is 999x999 array too large or is a single 999 array too large?


    Maybe you could tell me which OS and Compiler you are using? I'm working on
    arrays that are much larger and got no "array too large" error so far.

    --
    Dipl.-Inform. Hendrik Belitz
    Central Laboratory of Electronics
    Research Center Juelich
     
    Hendrik Belitz, Dec 19, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luigi Donatello Asero

    Are these pictures too dark or/and too large?

    Luigi Donatello Asero, May 19, 2004, in forum: HTML
    Replies:
    13
    Views:
    934
    Mabden
    May 21, 2004
  2. Luigi Donatello Asero

    Re: Are these pictures too dark or/and too large?

    Luigi Donatello Asero, May 21, 2004, in forum: HTML
    Replies:
    0
    Views:
    666
    Luigi Donatello Asero
    May 21, 2004
  3. shreesh

    ARRAY SIZE TOO LARGE

    shreesh, Sep 1, 2006, in forum: C Programming
    Replies:
    11
    Views:
    735
    Sjouke Burry
    Sep 1, 2006
  4. Dag Sunde
    Replies:
    4
    Views:
    376
  5. shin82

    problem with constant too too large

    shin82, Oct 31, 2012, in forum: C Programming
    Replies:
    0
    Views:
    375
    shin82
    Oct 31, 2012
Loading...

Share This Page