Array Sizing

This is a discussion on Array Sizing within the C++ Programming forums, part of the General Programming Boards category; Ok, here goes... I have read and searched several threas here that are concerned with the size of arrays and ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    5

    Array Sizing

    Ok, here goes...

    I have read and searched several threas here that are concerned with the size of arrays and how they should not be too large. I have seen that an answer to this is vectors. I have absolutely no idead what vectors are. What I want to do is have three single dimension arrays that are size 1,000,000. Yes, I know this is probably a bad way to do it but it is also a very simple way to do what I want. I guess out of all of my ramblings the question is how do I get Microsoft Visual C++ 6.0 to accept this array size?

    Thank you,

    Elliott

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,505
    The usual problem is one of running out of stack space when you make such large arrays local parameters to a function.
    For example, this is generally a bad idea
    Code:
    int main ( ) {
      int big[1000000];
    }
    You can make them static, which preserves scope, but does not actually place them on the stack, like so.
    Code:
    int main ( ) {
      static int big[1000000];
    }
    If you don't know how many you need until the program is running, then you have to dynamically allocate them.
    Code:
    int main ( ) {
      int howmany = 1000000; // or however you work it out.
      int *big = new int[howmany];
    }
    No matter which way you go, you still have big[index] type access and any of them can be passed (as a pointer) to other functions without rewriting the function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 02:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

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