我有一个很棒的小AutoIt脚本,我在过去的几年里一直在使用它。它最初是为Skype构建的,用于将占用RAM的应用程序的内存使用量减少到他们需要的最低限度(仅适用于Windows ),并将其保持在尽可能低的水平,只给他们真正需要的东西。它看起来是这样的:
#include <Misc.au3>
_Singleton("skype-memory-reducer")
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
TrayCreateItem("Quit")
TrayItemSetOnEvent(-1, "Bye")
TraySetState()
Global Const $interval = 2000 ; interval at which the memory is freed, anything below this will almost certainly only slow down your system.
;here you can add any other process,
;but be carefull which process you choose,
;bacause in some cases this will slow down your application or even your PC
Global $list = "skype.exe|skypePM.exe"
Global $processlist = StringSplit($list, "|")
While 1
For $i = 1 To UBound($processlist) - 1
$pid = ProcessExists($processlist[$i])
If $pid Then _ReduceMemory($pid)
Next
_ReduceMemory(); also reduce the memory used by the script itself...
Sleep($interval)
WEnd
Func Bye()
Exit
EndFunc ;==>Bye
;I don't remember who was the author of this UDF... (it's not me)
Func _ReduceMemory($i_PID = -1)
If $i_PID <> -1 Then
Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
Else
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
EndIf
Return $ai_Return[0]
EndFunc ;==>_ReduceMemory 现在,我正在寻找尝试完成相同的事情,但严格地使用Python。要么是通过Python中完全原生的东西,要么是可以在Python中运行Autoit脚本而不需要调用另一个进程的东西。
感谢您的帮助,谢谢!
编辑:以防万一,我希望我的应用程序最终是可移植的。因此,我尽量避免在Windows中注册任何DLL(以防有人考虑使用Win32模块),再次谢谢!
发布于 2012-04-01 05:48:05
您可以使用ctypes模块来访问Windows DLL。这将允许您重写_ReduceMemory函数。程序的其余部分似乎相当微不足道。
https://stackoverflow.com/questions/9959618
复制相似问题