AutoHotkey Community

It is currently May 26th, 2012, 5:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: DLL cache
PostPosted: July 4th, 2005, 10:34 am 
Offline

Joined: June 16th, 2005, 12:23 pm
Posts: 92
Sounds intimidating but should in fact be pretty easy and straighforward to implement. Here's a rough sketch: whenever there is a DLLCall() the C++ code should do a LoadLibrary() for the DLL in question, up to a maximum of say, three or four DLLs. When four DLLs are loaded and there is another call to DLLCall() with a fifth DLL, the first one loaded is freed and the fifth is loaded. Etc. In effect this means that the last three or four DLLs stay loaded.

This should make explicit LoadLibray() calls almost a thing of the past. Another advantage would be that this would automatically speed up all scripts that use DLLCall(), even if the author couldn't be bothered to call LoadLibrary() himself.

There may be very subtle side effects, but I think in general this "caching" should be no problem. However, if there are issues, perhaps a new function DLLCall2() could be used.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2005, 2:51 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
It's a good idea. The thing that bothers me about it is that all cached DLLs would stay in memory until the script exits, which probably increases memory usage (perhaps someone could test this on a largish DLL).

In addition, unless a new command were added to free the cached libraries, there would be no way to free them without exiting the script.

A good compromise might be to have a new option in the last parameter that specifies whether the DLL should stay cached until the script exits.

Thanks for suggesting it. More comments are welcome from anyone.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2005, 3:57 pm 
Offline

Joined: June 16th, 2005, 12:23 pm
Posts: 92
Chris wrote:
all cached DLLs would stay in memory until the script exits

True. That shouldn't be much of a problem for scripts that do something and relatively quickly exit. But a script that runs all day (I have a few fairly large ones that run continually) might be a different story.

One solution could be to free these DLLs after a given period of time: if there have not been any DLLCall()s for say five minutes, they are freed. This of course would make the implementation more difficult.

Quote:
A good compromise might be to have a new option in the last parameter that specifies whether the DLL should stay cached until the script exits.

That's probably the way to go. It is only half-automatic but this should be fine.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2005, 4:35 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
thomasl wrote:
One solution could be to free these DLLs after a given period of time: if there have not been any DLLCall()s for say five minutes, they are freed.
Nice. This makes automatic caching more attractive as the default behavior (perhaps this default could be overridden via option).

Although these are ingenious ideas, and although there is clearly a benefit to caching, I still have some doubt that it's worth the extra code size and documentation complexity. Opinions from anyone else would be welcome.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2005, 4:45 pm 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Since thomasl is going to include RegEx with the help of DLLCall. I assume it will make a big difference if the dll is cached.

I think an automatic freeing after a period of time is not neccessary. Only an option to free the memory. The coder has to specify this explicitly. This way, it is clean and saves AHK the code and docs.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2005, 1:00 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2542
Couldn't this already be done in a script by using DllCall with FreeLibrary? Maybe I'm misunderstanding the end result but it sounds like a function and a timer would have the same result...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2005, 1:15 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
My interpretation is that the primary goal is to accelerate scripts that use DllCall yet do not call LoadLibrary and FreeLibrary. So it's a convenience feature that would boost performance without the script author having to worry about which DLLs need to be kept resident, and when to free them.


Last edited by Chris on July 6th, 2005, 2:16 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2005, 12:43 pm 
Offline

Joined: June 16th, 2005, 12:23 pm
Posts: 92
Chris wrote:
My interpretation is that the primary goal is to accelerate scripts that use DllCall yet do not call LoadLibrary and FreeLibrary.

Your interpretation is correct. It would not cost much, be easy to do and is convenient. What more can one ask for? :)

I think DLLCall() is among the most underestimated features of AHK: instead of enlarging the core one should try to provide nice bindings to external stuff (ie DLLs). Almost everything has already been invented by someone else.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group