Home > Back-end >  Always appear out of the memory sometimes have something no phenomenon
Always appear out of the memory sometimes have something no phenomenon

Time:10-03

Procedure TForm1. Button1Click (Sender: TObject);
Type
ARR1=ARRAY OF integer;
ARR2=ARRAY OF real;
ARR3=ARRAY OF an ARRAY OF integer;
ARR4=ARRAY OF an ARRAY OF real;
Var
Partsum, sum: extended;
Num, hang: longint;
Ff, Qu, NCMAX, M, N, inttao, alph, k, I, j, ALL, a, e, NC: integer;
FFF, rou, aipu Bmins, p, q, a0, a1, a2, a3, a4, a5, b0, b1, b2, b3, c0, c1, c2 and c3: real;
Route: ARR3;
Tao1 tao2, detatao1 detatao2: ARR4;
Pper, per mins, r, t, rs, WQ, u, W, s, the rsei, BESTS, BESTT, WS, WT: ARR2;
The begin
Rou:=0.7; Qu:=10; Aipu:=0.000001; NCMAX:=200; M:=20; N:=10;
Inttao:=1; Alph:=1; A0:=0.57721566; A1:=0.99999193; A2:=0.24991055; A3:=0.05519968;
A4:=0.00976004; A5:=0.00107857; B0:=0.2677737343; B1:=8.6347608925; B2:=18.059016973;
B3:=8.5733287401; C0:=3.9584969228; C1:=21.0996530827; C2:=25.6329561486; C3:=9.5733223454;

Setlength (route, M + 1, 3);
Setlength (tao1, 1, 11);
Setlength (tao2, 11, 11);
Setlength (detatao1, 1, 11);
Setlength (detatao2, 11, 11);
Setlength (pper, 12);
Setlength (per, 11);
Setlength (mins, M + 1);
Setlength (r, ALL);
Setlength (t, ALL);
Setlength (rs, ALL);
Setlength (WQ, ALL);
Setlength (u, ALL);
Setlength (W, ALL);
Setlength (s, ALL);
Setlength (rsei, ALL);
Setlength (BESTS NCMAX + 1);
Setlength (BESTT NCMAX + 1);
Setlength (WS, 11);
Setlength (WT, 11);

For I:=0 to 10 do
The begin
WS: [I]=0.1 * I/N;
end;
For j:=0 to 10 do
The begin
WT: [j]=1000 * j/N;
end;
NC:=0;
BESTS. [NCS] :=0.03;
BESTT (NC) :=48;
If (WS [10] - WS [0])/N>=aipu then
The begin
If NC> 0 then
The begin
If (BESTS (NC) - trunc (BESTS/NC)=0) and (BESTS (NC) & lt;> BESTS [1] NC) then

For I:=0 to 10 do
The begin
WS: [I]=BESTS (NC) - 5 + I;
Memo1. Lines. The Add (floattostr (WS) [I]);
End
The else
For I:=0 to 10 do
The begin
P:=I;
For: e=0 to CAL (BESTS/NC) do
The begin
P:=p/10;
end;
WS: [I]=BESTS (NC) + p;
Memo1. Lines. The Add (floattostr (WS) [I]);
end;
end;
If NC=0 then

The begin
If BESTS (NC) - trunc (BESTS/NC)=0 then

For I:=0 to 10 do
The begin
WS: [I]=BESTS (NC) - 5 + I;
Memo1. Lines. The Add (floattostr (WS) [I]);
End
The else
For I:=0 to 10 do
The begin
P:=I;
For: e=0 to CAL (BESTS/NC) do
The begin
P:=p/10;
end;
WS: [I]=BESTS (NC) + p;
Memo1. Lines. The Add (floattostr (WS) [I]);
end;
end;
end;

If (WT [10] - WT [0])/N>=aipu then
The begin
If NC> 0 then
The begin
If (BESTT (NC) - trunc (BESTT (NC))=0) and (BESTT (NC) & lt;> BESTT [1] NC) then
For j:=0 to 10 do
The begin
WT: [j]=BESTT (NC) - 5 + j;
Memo2. Lines. The Add (floattostr (WT) [j]);
End
The else
For j:=0 to 10 do
The begin
Q:=j;
For: e=0 to CAL (BESTS/NC) do
The begin
Q:=q/10;
end;
WT: [j]=BESTT (NC) + q;
Memo2. Lines. The Add (floattostr (WT) [j]);
end;
end;
If NC=0 then
The begin
If (BESTT (NC) - trunc (BESTT (NC))=0) then
For j:=0 to 10 do
The begin
WT: [j]=BESTT (NC) - 5 + j;
Memo2. Lines. The Add (floattostr (WT) [j]);
End
The else
For j:=0 to 10 do
The begin
Q:=j;
For: e=0 to CAL (BESTT/NC) do
The begin
Q:=q/10;
end;
WT: [j]=BESTT (NC) + q;
Memo2. Lines. The Add (floattostr (WT) [j]);
end;
end;
end;
end;


I am a little white, Delphi beginners, separate debugging this short program, sometimes can run out the data for the first time, but after running again complains: out of memory! Excuse me what reason??

CodePudding user response:

Eldest brother, you really are a novice?

CodePudding user response:

reference 1st floor u012518993 response:
eldest brother, you really are a novice?

Is!!! What is the cause the problem??

CodePudding user response:

To solve the problem before, at least the code optimization first:
Remove duplicate code, extraction method, the if (WT [10] - WT [0])/N>=aipu then code and the if (WS [10] - WS [0])/N>=aipu then code is completely repeated, extract a son for method, parameter as an array; Memo2. Lines. The Add (floattostr (WT) [j]); Convenient method can separate a child, unified management, is conducive to the follow-up maintenance;
To give priority to the CPU supports data types: why need to use Real, without considering the accuracy of double or single?
Code, some variables can be declared extraction as constants, especially SetLength set the array length of several variables;
-- -- -- -- -- -- -- -- -- --
All in all, keep the clarity of the code, convenient himself, others,

On the issue of the errors, the reason is that your "All" uninitialized variable , is likely to be any kind of value; Each time, because the stack the value of the different and different, a bad situation, will be out of the memory,
  • Related