View previous topic :: View next topic |
Author |
Message |
Daniel3 How do I cheat? Reputation: 0
Joined: 04 Apr 2020 Posts: 6
|
Posted: Thu Jan 21, 2021 9:42 pm Post subject: Slow freeing of Widestring array in Delphi 7 |
|
|
When freeing 2 million AnsiString array entries the compiler eventually calls freemem. 2 million entries are freed in under 1 second.
When freeing 2 million widestring array entries - same code - it takes FOREVER. It removes around 1 mbyte a second... and takes around 20-30 seconds. It's really slow.
The compiler seems to call "sysfreestring" instead of freemem and this is the bottleneck. Is there any reason why?
It doesn't matter what method I use to free the array [array:= nil, setlength(array, 0), array[i]:= '') it will always take forever.
Better yet, is there a way around this?
--btw I am using 2 mil for testing purposes... even freeing 20,000 is unacceptably slow.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Fri Jan 22, 2021 1:18 am Post subject: |
|
|
try allocating memory yourself and assign pwidechar inside that memory.
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Daniel3 How do I cheat? Reputation: 0
Joined: 04 Apr 2020 Posts: 6
|
Posted: Fri Jan 22, 2021 5:15 am Post subject: |
|
|
Hmm I'm aware how to allocate memory, but what if I am assigning a static array ? The only way I can create it in the first place is using the delphi compiler?
a: array [0.1000] of WideString
How would one manage the memory themselves for that? Or are you saying I need to have a size var and continually allocate memory to each string added and deallocate when I want to remove. Sounds tricky with arrays.
perhaps something like this?
Code: |
Var
MyArray: array[0..2000000] of Pointer;
procedure TForm1.Button9Click(Sender: TObject);
var
w: widestring;
i: Longint;
begin
w:= 'hello';
for i:= 0 to 2000000 do
begin
MyArray[i]:= AllocMem(length(w) * sizeof(w));
MoveMemory(MyArray[i],PWideChar(w), length(w) * sizeof(w));
end;
MessageBoxW (0,PWidechar(MyArray[0]),0,0);
for i:= 0 to 2000000 do
freemem(MyArray[i]);
end; | [/code]
Seems to work - I could obviously make this into a proper array create function - but is this the best way?
|
|
Back to top |
|
|
Daniel3 How do I cheat? Reputation: 0
Joined: 04 Apr 2020 Posts: 6
|
Posted: Fri Jan 22, 2021 5:25 pm Post subject: |
|
|
Also looks like it should be
MyArray[i]:= AllocMem(length(w) * 2;
MoveMemory(MyArray[i],PWideChar(w), length(w) * 2);
|
|
Back to top |
|
|
|