Thread: Max Array?

  1. #1
    Registered User
    Join Date
    Jan 2002

    Max Array?

    I am reading data from a file and i need to read in a lot of data, approaching millions of lines proabably.

    the problem i have is i have declared a struct to store the data but i have found that the maximum array of structs i can have is:

    users db[28725] ;

    Anyone know why this is and how i can change it to accept a larger amount of data. my struct is simple:

    struct users
    	string user ;
    	char ip[20] ;
    } ;
    Thanks Guys

  2. #2
    Registered User
    Join Date
    Apr 2002
    Use dynamic memory allocation. Its pretty simple. You just determine how many structs you are going to require then allocate that much room...

    // init size to whatever you need at run-time
    users *pUsers = new users[ size ];
    if( !pUsers )
      // couldn't allocate memory...
    delete [] pUsers;

  3. #3
    Registered User
    Join Date
    Jan 2002
    Thanks MrWizard dynamic memory allocation worked a treat.

    Salem: Interesting to know that, any idea how you can change the limits imposed by the OS/Compiler or are they set.

    Thanks a lot for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. linked list inside array of structs- Syntax question
    By rasmith1955 in forum C Programming
    Replies: 14
    Last Post: 02-28-2005, 05:16 PM
  3. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  4. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  5. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM