|
|
вернуться в форумMinimum memory allocation? Послано Dizzy 6 дек 2008 04:18 Why does dynamic array (double *a = new double [256*1024*4]) work but double a[256*1024*4] doesn't? Or more exactly why does it inflict stack overflow? Does it allocate more memory or maybe use another memory? Edited by author 06.12.2008 06:52 Re: Minimum memory allocation? Послано Dizzy 6 дек 2008 10:19 I found! ________________________ double a[256*1024*4]; void main(){ ... } ________________________ will work, but void main(){ double a[256*1024*4]; ... } won't! Stack overflow! Can anybody add somthing else? Edited by author 06.12.2008 10:28 Re: Minimum memory allocation? Local variables are allocated on the stack, new double[] allocates from the heap, global varitables are allocated.. well.. um... not on the stack ;-) You can increase stack size by using pragmas or (more portable) extern int _stklen=8888888; Read FAQ also. Re: Minimum memory allocation? update: _stklen is nonportable too. Re: Minimum memory allocation? ))) Third type of variables(global) are allocated in the memory called static... And if you want you to write excelent programs on C++, you must to learn a lot about memory allocation )) And as always pieces of advice: (off-top) read Richter Jeffrey, Bruce Ekkel, Nikolai Jossatis, Aleksandresku - and problems in C++ will disappear. And you'll have algorithm-making problem only ))) |
|
|