ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1001. Обратный корень

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?
Послано Anisimov Dmitry (Novosibirsk STU) 6 дек 2008 21:40
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?
Послано Anisimov Dmitry (Novosibirsk STU) 6 дек 2008 21:54
update: _stklen is nonportable too.
Re: Minimum memory allocation?
Послано Bohdan_prisoner 13 дек 2008 03:40
)))
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 )))