Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Slow freeing of Widestring array in Delphi 7

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Daniel3
How do I cheat?
Reputation: 0

Joined: 04 Apr 2020
Posts: 6

PostPosted: Thu Jan 21, 2021 9:42 pm    Post subject: Slow freeing of Widestring array in Delphi 7 Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Fri Jan 22, 2021 1:18 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Daniel3
How do I cheat?
Reputation: 0

Joined: 04 Apr 2020
Posts: 6

PostPosted: Fri Jan 22, 2021 5:15 am    Post subject: Reply with quote

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? Shocked Laughing
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
View user's profile Send private message
Daniel3
How do I cheat?
Reputation: 0

Joined: 04 Apr 2020
Posts: 6

PostPosted: Fri Jan 22, 2021 5:25 pm    Post subject: Reply with quote

Also looks like it should be

MyArray[i]:= AllocMem(length(w) * 2;
MoveMemory(MyArray[i],PWideChar(w), length(w) * 2);
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites