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

CodePudding user response:

You should use TList this

CodePudding user response:

The
reference 3 floor zzandzry response:
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


This is too much memory fragments, you actually not much total
You are the second one-time accurate open space
I said is don't know the accurate space, but also makes the memory fragments will not too much
The practice of Tlist will like me, so not too much

CodePudding user response:

reference 5 floor sz_haitao reply:
reference zzandzry reply: 3/f 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

This is too much memory fragments, you actually not much total
You are the second one-time accurate open space
I said is don't know the accurate space, but also makes the memory fragments will not too much
Fragments Tlist will like me, so not much


I see what you mean

CodePudding user response:

See this suddenly thought of a problem:
SetLength repeated open space, if there are data in the space, not clear?

CodePudding user response:

refer to 7th floor hongss response:
see that suddenly thought of a question:
SetLength repeated open space, if there are data in the space, not clear?


Will, of course, copying the data in the past, so you have to open up new first, then release the old, thus formed

CodePudding user response:

Repeated use should consider applying for a block of memory, but not again and again to apply for,

CodePudding user response:

WIN764 XE3 I am running on my machine error until 22 million. Committed memory reached 1.6 G
Compiled into a 64 - bit program, as a result of a 64 - bit memory access amount is too large, I waited for a few minutes also didn't appear memory use, end program.

Convert TList Or deposit TList structure pointer result worse only 16 million

In my machine, for example, 22 million when, in fact, when setlength 44 million this structure exists. The highest peak is too much for memory also belongs to the normal.

Like the original poster memory will not end this way, if you really need a huge amount of data does not generally all processed by memory. For example is essentially and Oracle data program must be put on the disk, memory, that is, put some indexes, and the commonly used buffer.

CodePudding user response:

Use TList, more simple,,

CodePudding user response:

TList or use the generic

CodePudding user response:

Upstairs to get too complicated, so, don't use record, you declare a class from TCollectionItem inheritance, the item you need statement into the field or property, use TCollection rather than a List to manage these objects, so that the memory efficiency is higher,

CodePudding user response:

Unlimited data up space, of course, I'll overflow,
  • Related