Rorax Posted October 26, 2006 Share Posted October 26, 2006 (edited) Good day! Doesnt mather if a script only contains: sleep(3000000) It will still use around 5mb of memory when being run. Is there a way to make it use less memory when not active? I'm doing a script that monitors a network path for new files (checks every 30sec if files exist) and then move the files to the users home folder. But it is taking up about 5-6mb of memory (some machines are VERY old so 5-6mb is a lot). So is there a way to limit the memory usage of the script lets say during the sleep phase? Or is there a godsend way to only start the script when a file is in the network folder? Basically its like this: a) Users scanns a document Document is saved in the scanners harddrive c) Script moves documents from scanners harddrive to users homefolder Regards, Rorax Edited October 26, 2006 by Rorax Link to comment Share on other sites More sharing options...
GaryFrost Posted October 26, 2006 Share Posted October 26, 2006 Func _ReduceMemory() Local $ai_Return = DllCall($dll_mem, 'int', 'EmptyWorkingSet', 'long', -1) If @error Then Return SetError(@error,@error, 1) Return $ai_Return[0] EndFunc ;==>_ReduceMemory SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GaryFrost Posted October 26, 2006 Share Posted October 26, 2006 (edited) HotKeySet("{Esc}", "_Terminate") $dll_mem = DllOpen(@SystemDir & "\psapi.dll") If $dll_mem <> - 1 Then AdlibEnable("_ReduceMemory", 60000) While 1 Sleep ( 200 ) Wend DllClose($dll_mem) Func _ReduceMemory() Local $ai_Return = DllCall($dll_mem, 'int', 'EmptyWorkingSet', 'long', -1) If @error Then Return SetError(@error,@error, 1) Return $ai_Return[0] EndFunc ;==>_ReduceMemory Func _Terminate() Exit EndFunc Edited October 26, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
jpm Posted October 26, 2006 Share Posted October 26, 2006 I am a little bit confuse on my Windows XP/Sp2 this does not reduce anything. Back to the question, on the same system it use 3072K. AutoIt try to allocate memory when it need it. I don't know if we can really go much down. If Windows need the memory it will reduce automatically the working set of an idle process : autoIt stop in Sleep is one. So the memory can be used by other application. Link to comment Share on other sites More sharing options...
GaryFrost Posted October 26, 2006 Share Posted October 26, 2006 I am a little bit confuse on my Windows XP/Sp2 this does not reduce anything.Back to the question, on the same system it use 3072K. AutoIt try to allocate memory when it need it.I don't know if we can really go much down.If Windows need the memory it will reduce automatically the working set of an idle process : autoIt stop in Sleep is one.So the memory can be used by other application.The code above does work on Windows XP SP2, the above is not set to reduce memory untill the script has been running for 1 minute.I did that way to show the user that it does reduce the memory used. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
jpm Posted October 26, 2006 Share Posted October 26, 2006 The code above does work on Windows XP SP2, the above is not set to reduce memory untill the script has been running for 1 minute.I did that way to show the user that it does reduce the memory used.I just notice the 60000. I works pretty good. Perhaps I can add such Working set management if the script as for a big sleep Link to comment Share on other sites More sharing options...
Rorax Posted October 31, 2006 Author Share Posted October 31, 2006 Thanks for the help, I'll check it out! Link to comment Share on other sites More sharing options...
Cool1Net6 Posted December 4, 2006 Share Posted December 4, 2006 Hey gafrost. I modified your code as follows... Func _ReduceMemory() $dll_mem = DllOpen(@SystemDir & "\psapi.dll") Local $ai_Return = DllCall($dll_mem, 'int', 'EmptyWorkingSet', 'long', -1) If @error Then Return SetError(@error,@error, 1) DllClose($dll_mem) Return $ai_Return[0] EndFunc ;==>_ReduceMemory You need the DllOpen command for it to work. I want to stick this in an infinite loop. Will it cause any adverse effects running this around every 20 seconds? -Cool- Link to comment Share on other sites More sharing options...
GaryFrost Posted December 4, 2006 Share Posted December 4, 2006 Hey gafrost. I modified your code as follows... Func _ReduceMemory() $dll_mem = DllOpen(@SystemDir & "\psapi.dll") Local $ai_Return = DllCall($dll_mem, 'int', 'EmptyWorkingSet', 'long', -1) If @error Then Return SetError(@error,@error, 1) DllClose($dll_mem) Return $ai_Return[0] EndFunc ;==>_ReduceMemory You need the DllOpen command for it to work. I want to stick this in an infinite loop. Will it cause any adverse effects running this around every 20 seconds? -Cool- If your going to call it that much I sugges opening the dll before the loop and closing it after the loop. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Snarg Posted December 4, 2006 Share Posted December 4, 2006 Reduce Memory UDF. A little reading goes a long way. Post count means nothing. Link to comment Share on other sites More sharing options...
Valik Posted December 4, 2006 Share Posted December 4, 2006 Doesn't the fact that the process loads some stuff back into memory clue you in that maybe it needs that stuff? Emptying the working set every once in awhile to clear out unused stuff is an acceptable use. Doing it ever 20 seconds is just dumb. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now