The limit is system (not only hardware, but also software, notably operating system and runtime) specific. See also this question very similar to yours.
You should try hard to avoiding too big call stack frames. These days on desktop or server machines, I would recommend at most a few dozen kilobytes for the biggest call stack frames (and very often much less, i.e. hundreds of bytes) - notably for intermediate - non-leaf- or recursive functions. A typical system has a machine stack able to grow to a few megabytes (but on embedded microcontrollers, or inside the Linux kernel, it could be a few kilobytes!). With multi-threaded applications it should be a little less (since each thread has its own stack).
On Linux and Posix systems you can use the setrlimit(2) syscall with RLIMIT_STACK
to lower (and perhaps sometimes to slightly increase) the stack limit. In your terminal with a bash
shell, use the ulimit -s
builtin.
The following GCC options could interest you: -fstack-usage
, -Wframe-larger-than=
, -fstack-split
In your code, consider replacing
string string_array [STRING_ARRAY_SIZE];
with
vector<string> string_vector;
and replacing
string_array[i] = line;
i++;
with
string_vector.push_back(line);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…