调试器异常错误和内存溢出 [英] Debugger Exception Error and memory overshoot
本文介绍了调试器异常错误和内存溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图运行以下代码,但它显示了一个关于内存地址的错误,并显示一条消息,可能在循环后不定义。请看看。
var n_max:integer;
n:整数;
r,R1,f,h0:Real的数组;
const
h = 0.00889; nip = 100;
cod = 10;
rod = 76;
nip_dia = 5;粘度= 0.001;速度= 76;
begin
n_max:= Round(((rod-cod)/ 2)/ h);
for n:= 0 to n_max-1 do;
r [n]:= cod / 2 + h * n;
R1 [n]:=(r [n] *(nip_dia)/ 2)/(r [n] +(nip_dia)/ 2);
f [n]:= nip *((r [n] -r [0])/ r [n]);
h0 [n]:= 4 *粘度*速度*(1 /(60 *(R1 [n] / f [n])));
WriteLn(r [n]);
WriteLn(R1 [n]);
WriteLn(f [n]);
WriteLn(h0 [n]);
ReadLn;
结束。
解决方案
您不会为数组分配任何内存。您需要调用 SetLength
来做到这一点。
SetLength(r,n_max);
//同样为其他数组
此外,循环什么都不做。该循环包含一个单独的语句,这是一个空的语句,在 do
之后由分号终止。
<$ p $对于n:= 0到n_max-1,p>
//是的,分号是循环结束
你会需要一个开始
/ end
block。
for n:= 0 to n_max-1 do
begin
//循环体在这里
....
end;
//在这一点上,在循环之外,n的值是不明确的。
I tried to run the following code but it shows an error regarding memory address and shows a message that 'n maybe undefined after the loop'. Please have a look.
var n_max : integer;
n: integer;
r, R1, f, h0 : Array of Real;
const
h = 0.00889; nip= 100;
cod = 10;
rod = 76;
nip_dia = 5; viscosity = 0.001; velocity = 76;
begin
n_max := Round(((rod-cod)/2)/h);
for n := 0 to n_max-1 do;
r[n]:= cod/2 + h*n;
R1[n] := (r[n]*(nip_dia)/2)/(r[n]+(nip_dia)/2);
f[n] := nip*((r[n]-r[0])/r[n]);
h0[n] :=4*viscosity*velocity*(1/(60*(R1[n]/f[n])));
WriteLn(r[n]);
WriteLn(R1[n]);
WriteLn(f[n]);
WriteLn(h0[n]);
ReadLn;
end.
解决方案
You don't allocate any memory for the arrays. You need to call to SetLength
to do that.
SetLength(r, n_max);
// and likewise for the other arrays
What's more, the loop does nothing. The loop contains a single statement which is an empty statement terminated by the semi-colon after the do
.
for n := 0 to n_max-1 do;
// yes, that semi-colon is the end of the loop
You'll need a begin
/end
block.
for n := 0 to n_max-1 do
begin
// loop body goes in here
....
end;
// at this point, outside the loop, the value of n is ill-defined.
这篇关于调试器异常错误和内存溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文