Max Array?

This is a discussion on Max Array? within the C++ Programming forums, part of the General Programming Boards category; I am reading data from a file and i need to read in a lot of data, approaching millions of ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    64

    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:

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

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

    Code:
    // 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
    Posts
    64
    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, 08: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, 01:04 PM
  4. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 01:44 AM
  5. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 05:27 PM

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