Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

float something[1000][1000]?

Status
Not open for further replies.

rastkocvetkovic

Programmer
Aug 11, 2002
63
SI
Why is this a problem in Visual Studio 6.0? The problem just crashes (Report Error to Microsoft). The size shouldn't be a problem - I think we've all seen arrays longer than 1000*1000.

Thank you for help!
 
Actually, try to compile this:

void OutputSomething() {
//float something[360][360]; //case ONE
flat something[359][359]; //case TWO
something[34][24] = 0.9;
printf("Output: %f\n\n", something[34][24]);
}

case ONE (parameter >= 360) doesn't work.
case TWO (parameter < 360) works.

360*360 < 2^17.
359*359 < 2^17. => there is no logical border in indexing!
 
I tried out your code (as a console application) and it worked for both cases.

I'm guessing that the problem lies with the fact that you are blowing the 'stack'. Each 'float' takes 4 bytes of stack so 1000*1000*4 = 4,000,000 bytes and 'default' stack size is only 1MB.

You can increase the stack size within the project settings but be careful if you are using incremental linking - the new stack size is ignored until a full link is performed.

Alternatively you can use EDITBIN to change the stack size outside of Visual Studio.
 
Don't use huge local arrays, allocate them dynamically using new.
 
Yes rastkocvetkovic I need a sample where i can allocate with new ,an array to a pointer.
and Temps is right
Make off &quot;Link Inceremently&quot; then ....
Project->Settings->Links->Outout--Reserve..and assign a new stack allocation in integer.
Of Course your code need stack size more spacious then default allocation

awaiting minigis's reply


use this code
 
To allocate dynamically use the following syntax for a float array of 1000 by 1000:-

float (*something)[1000];
something = new float[1000][1000];

something[34][24] = 0.9f;
printf(&quot;Output: %f\n\n&quot;, something[34][24]);

delete [] something; // for completeness
 
Same applies for any dynamically allocated multi-dimensional array. So for a 1000*1000 char array:-

char (*something)[1000];
something = new char[1000][1000];

something[34][24] = 'z';
printf(&quot;Output: %c\n\n&quot;, something[34][24]);

delete [] something;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top