![]() |
|
#1
|
|||
|
|||
What's wrong with this 3D array declaration?Hi,
I am trying to declare a 3D array with the size of 6,400 and 400 in each dimension using the code as following: CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: What's wrong with this 3D array declaration?Quote:
In VS2005 a "short" is 16 bits long, so this array requires 1,920,000 bytes in memory. In just about all implementations (and certainly for VS2005) variables declared like this are allocated storage on a stack. See Footnote. The total default stack size for Microsoft 32-bit compilers is usually something like a Megabyte, so this won't work. To tell the compiler/linker to use a larger stack see, for example, Visual C++: Set Stack Size One "easy" solution that doesn't require a large stack size is to declare the array to be static. CPP / C++ / C Code:
Now, "easy" is sometimes "best" and sometimes not. For example, if you had several functions that allocated the storage for local use within the function, "static" is probably not the way to go. For this compiler you can make the stack size larger. An alternative would be to use dynamic allocation. On the other hand, if you just have one fixed-size array in your program, a default stack size and a "static" array may very well be practical. Regards, Dave Footnote: Things they don't always tell you in beginning programming class: If your program is going to need more than a few hundred K bytes of storage for variables, consider using dynamic array allocation (using new for C++ and malloc() or calloc() for C programs). Sometimes static storage will work, and I think it will for your problem, but the bottom line is that it is the programmer's responsibility to be aware of the program's resource requirements. Last edited by davekw7x : 23-May-2009 at 11:26.
|
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| run script command on ns2.26 | newbie06 | Computer Software Forum - Linux | 65 | 19-Aug-2009 08:50 |
| Giving garbage value as the result of product | winner | C Programming Language | 10 | 19-Jul-2008 02:47 |
| Error C2374 | lolp1 | C++ Forum | 3 | 25-May-2008 17:40 |
| i need help in C++ PLZ | its_me | C++ Forum | 3 | 04-Dec-2006 22:51 |
| Combining Vectors and References | Frankg | C++ Forum | 7 | 14-Jan-2006 07:17 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The