Jump to content

DLLCall Starts Off Strong Then SLOOOOOWS


NU2
 Share

Recommended Posts

I have a simple .au3 script that is as follows:

DllCall("<dll path>.dll", "int", "SetBool", "Int", 12, "Int", 1)

It works great for the first 50k iterations. Return is between .4 - .9 seconds. Then the return starts taking around 2.6 - 3.9 seconds.

I can't figure out what is causing the issue.

I have tried restarting the PC hoping that something in memory gets reset but to no avail.

The dll is compiled in C.

I have also tried to use the DLLOpen and DLLClose and use the $dll in the DLLCall instead of just the DLLCall with the dll path.

Is there some sort of log or something that is maxing out that I'm missing?

I apologize if I have left out any information. Please let me know what additional information you need to help me debug. Like my user name implies, I'm new to this.

Thanks

Link to comment
Share on other sites

I don't think anything in AutoIt would cause that behavior. More likely related to the DLL itself.

Do you see a memory leak while it's running on Task Manager Processes tab?

Can you call the DLL from something else, like VB?

:graduated:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I don't think anything in AutoIt would cause that behavior. More likely related to the DLL itself.

Do you see a memory leak while it's running on Task Manager Processes tab?

Can you call the DLL from something else, like VB?

:graduated:

I haven't really seen a memory leak. I've been trying to figure out how to write a vbscript or something along those lines to call my dll function but I'm still digging.

Link to comment
Share on other sites

Just tested the dll call with another tool... The issue is definitely something with AutoIT. The second tool I am using the function is returning instantly.

Any ideas would be appreciated. I will continue to dig.

Thanks

Link to comment
Share on other sites

I have also tried to use the DLLOpen and DLLClose and use the $dll in the DLLCall instead of just the DLLCall with the dll path.

Post working example code that causes the problem.

The problem is in the response time of my application. This dll call just sets a buttons on off state. Can't really show the code but this is what I have tried for dll call.

I have tried both methods.

#1

DllCall("C:\Mydll\Mydll.dll", "Int", "SetBool", "Int", 16, "Int", 1)

#2

$dll = DllOpen("C:\Mydll\Mydll.dll")

DllCall($dll, "Int", "SetBool", "Int", 16, "Int", 1)

DllClose($dll)

Both are now SLOW. Same function call performed in a 3rd party tool comes back immediately.

Like I said, I had a loop of 50,000 DllCall() that work in .4 - .9 second range then it just started returning about 3.4 seconds. After restart and even after installing AutoIT on a second PC and performing the same test after 50k iterations, same out come.

You should instead use DllOpen and call DllCall with the handle. This should produce an immediate improvement.

Link to comment
Share on other sites

Like Richard said, if you are repeating the Open/Close cycle every time, you missed the point.

And when you tested it with "another tool" did you repeat it 50K times? Because you said your AutoIt script didn't become slow until some iterations had passed.

I seem to remember reading something on another topic about Windows "caching" closed handles for about 10 seconds to make sure new handles don't overlap invalid closed ones to quickly, or something like that. But the only way to hit that limit was fast open/close cycles in a tight loop. And that was a Windows issue, not AutoIt's.

:graduated:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Like Richard said, if you are repeating the Open/Close cycle every time, you missed the point.

And when you tested it with "another tool" did you repeat it 50K times? Because you said your AutoIt script didn't become slow until some iterations had passed.

I seem to remember reading something on another topic about Windows "caching" closed handles for about 10 seconds to make sure new handles don't overlap invalid closed ones to quickly, or something like that. But the only way to hit that limit was fast open/close cycles in a tight loop. And that was a Windows issue, not AutoIt's.

:graduated:

AH!! So I shouldn't be opening and closing the dll every call? I thought inside the DLLCall however, an open of the ddl was performed, then the function and then a close??

The other tool is still running. It's currently at 273,196 iterations and not a single slow down. I will have to do a search to see if I can find the Windows "caching" issue. The AutoIT DLLCall is exactly what I need to I'm hoping I can get this straightened out. I'll be sure to post a resolution if I find one and if any one has any additional thoughts please share.

Thanks again.

Link to comment
Share on other sites

AH!! So I shouldn't be opening and closing the dll every call?

Right! Open the DLL, call it in a loop and close the DLL when you exit your script:

$dll = DllOpen("C:\Mydll\Mydll.dll") ; Open the DLL when the script starts
While 1  ; Here starts your loop
    If $condition = True then ExitLoop ; Check condition. If true exit the loop
    DllCall($dll, "Int", "SetBool", "Int", 16, "Int", 1) 
Wend
DllClose($dll) ; Close the DLL before you exit the script
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

It's unnecessary.

DllOpen loads the dll for AutoIt (your process) into its own (your) address space. After the process exit there is no such space anymore, meaning dll is unloaded whether you like it or not. Besides that, it's reasonable to expect that AutoIt would do it for you on exit (help file).

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

It's unnecessary.

DllOpen loads the dll for AutoIt (your process) into its own (your) address space. After the process exit there is no such space anymore, meaning dll is unloaded whether you like it or not. Besides that, it's reasonable to expect that AutoIt would do it for you on exit (help file).

Sweet. Learn something new every day Posted Image

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...