-
运行时错误:
Stack
Overflow<
/p>
的解决办法
.txt
这世界上除了我谁都
没资格陪在你身边。
听
着,
我允许你喜欢我。
除了白头偕老,
我们没别的路可选了什么时候想嫁人了就告诉我
,
我娶
你。
现象:
编译正常通过,但运行时出现——
forrtl: severe (170): Program Exception
- stack overflow
Image PC Routine Line
Source
00401A73 Unknown Unknown
Unknown
004029B9 Unknown Unknown
Unknown
00449929 Unknown Unknown
Unknown
0042EDB9 Unknown Unknown
Unknown
77E7CA90 Unknown Unknown
Unknown
Incrementally linked image--PC
correlation disabled.
Press any key to
continue
解决方法:
在
project->settings->link->Ca
tegory=output->stack allocations
设一个足够大的值就行
参考:
/fortran/visual/vfn10/#Doctor
Issue
2001
/fortran
Doctor Fortran -
Don't Blow Your Stack!
Steve Lionel
Visual Fortran Engineering
Doctor frequently sees
questions like these, and he realizes it's time
for a
general article on the subject
of stack allocation, as well as the other
memory allocation types, static and
dynamic.
Static allocation
program's data - it has to
live somewhere in memory while it is being
referenced (registers are a special
kind of memory we won't get into here.)
The compiler, linker and operating
system work together to determine exactly
where in memory a piece of data is to
reside. The simplest method of
assigning locations is
fixed
(static) address by the compiler and linker in the
executable image
(EXE). For example,
if variable X is statically allocated at address
4000,
it is always at address 4000
when that EXE is run, no matter what else is
going on in the system. (DLLs can also
have static data - it is allocated at
a fixed offset from the base address
where the DLL gets loaded.)
Static allocation is simple from the
compiler's perspective because all that
is needed is to create a list of
variables that need allocation, and lay
them down in memory one after the
other. A run-time advantage of static
allocation is that it is usually easy
and fast to access a fixed address and
statically allocated data can be used
from anywhere in the program. But
static allocation has disadvantages
too. First, if you have any reentrant or
parallel code, the multiple codestreams
are both trying to use the same
data,
which may not be wanted. Second, if you have many
routines which need
a lot of memory
just while they're executing, the available
address space
can fill up quickly (for
example, ten routines each of which declares a
1000x1000 REAL(8) array need a total of
80,000,000 bytes just for those
arrays.) And perhaps most important,
with static allocation you must know at
compile-time how much memory you will
want.
Up through Fortran
77, the Fortran standard was carefully written in
a way
so that static allocation was
the only method needed. Even today, static
allocation is the most widely used
method - in Visual Fortran, COMMON blocks
and most variables with the SAVE
attribute are allocated statically. (Note
that Visual Fortran, by default,
implies SAVE for local routine variables
unless it can see that the variable is
always written before it is read.)
Dynamic allocation
Dynamic
allocation is the complete opposite of static
allocation. With
dynamic allocation,
the running application must call a system routine
to
request a particular amount of
memory (for example, 1000 bytes). The system
routine looks to see if that request
size is available in the collection
(
satisfied, a range of
memory addresses is marked as used and the
starting
address is returned to the
program. If the heap is empty, the operating
system expands the virtual address
space of the process to replenish the
heap, stopping only if there is no more
virtual memory available. The
program
stores the base address in a pointer variable and
then can access
the memory. When the
program no longer needs the memory, another system
routine is called to
used
again by a future allocate call. You can think of
this as similar to
borrowing money
from a bank, and then later paying it back (except
that
there's no interest!)