-
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
-
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.