Thread: Scope and Massive arrays

  1. #1
    Unregistered
    Guest

    Question Scope and Massive arrays

    I am writing a piece of code which has a 256 element long int array (long int SmallerArray[256]) which it reads from a file (this part works) and then creates an array of the above arrays of a size which is dependent on the file it reads. So it reads through the file twice, once looking for the total number of arrays, once to take the actual data into the arrays. So eventually it's sort of like this:
    long int *MassiveArray[totalNumArrays]
    where each element in MassiveArray is a pointer to an SmallerArray[256]. I need MassiveArray to be global, but I don't know the 'totalNumArrays' number until after I go through a function. Is there any way to define an array without actually saying how big it is?
    BTW, I can't stick a maximum value on MassiveArray like doing MassiveArray[1024] and then just using however much of it I need - it needs to be scalable according to the file's specifications.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    dynamic memory management with new[] and delete[] should do the trick for you, assuming you have enough RAM memory available. Look up dynamic memory/new and delete operators for arrays in your favorite textbook, tutorial, or bulletin board (hint: this ain't a bad place to start.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scope in ActionScript
    By sean in forum Tech Board
    Replies: 4
    Last Post: 09-03-2008, 04:14 PM
  2. Massive Function Problem
    By Marc Sharp in forum C Programming
    Replies: 10
    Last Post: 11-19-2003, 08:49 PM