Home > Back-end > About dynamic array of memory, everyone is how to solve?
About dynamic array of memory, everyone is how to solve?
Time:10-27
For example: To define a structure Type Ttest=record Id: dword; Name: string; Ege: word; Memo: string; end;
Var Atest: an array of ttest; I: integer; The begin I:=0; Isstop:=false; While isstop<> True do The begin Application. ProcessMessages; Inc (I); Setlength (atest, I); Atest [I - 1]. Id:=I; Atest [I - 1]. Name:='* *'; Atest [I - 1]. Ege:=20; Atest [I - 1]. Memo:='this is a test; Edit1. Text:=inttostr (I); end; end; //this dynamic defines the length Of the Atest, I run machine more than 17000 times will error Out Of the Memory Var Atest: an array of ttest; I, j: integer; The begin I:=0; Isstop:=false; J:=100000; Setlength (Atest, j); While iThe begin Application. ProcessMessages; Inc (I); Atest [I - 1]. Id:=I; Atest [I - 1]. Name:='* *'; Atest [I - 1]. Ege:=20; Atest [I - 1]. Memo:='this is a test; Edit1. Text:=inttostr (I); end; end; //such a set to 100000, will not be an error
Excuse me, are you how to solve the content of the newspaper after frequent setlength overflow error of
No points, gives the
CodePudding user response:
Setlength (atest, I); Too often, cause memory fragments too much!
CodePudding user response:
Really don't know the total number, every time can increase 50% (less than 1000, 1000), is not enough to add This can greatly reduce setlength number
CodePudding user response:
The to sz_haitao You say is I'm the second, I just want to know, what method can solve the out of memory error in the first method