Jump to content

--


AL3X
 Share

Recommended Posts

It reduces notepad to 88KB from 2962KB for me. I ran it this way:

$proceso = Run("C:\WINDOWS\notepad.exe")
Sleep(25000)
_ReduceMemory($proceso)
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()

They say that this function is not safe to use in some situations - the description of just where, is pretty technical.

But this function works great - we ought to all chip in and tip the guy that wrote it - a little gratuity!

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

I could be that it is best to use the full filepath of the executable when you launch it, before using _ReduceMemory() on a process:

$proceso = Run("C:\WINDOWS\notepad.exe")

You said you were having trouble with it when you launched the app this way:

$proceso = Run("notepad.exe")

But I am sure the experts would warn you against using _ReduceMemory on all your processes, but this has been tried before.

I was thinking of trying it on Internet Exporer because IE seems to use 27MB's sometimes.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

Sorry, but I think using this function is a stupid idea unless you really know what you want to do.

What benefits are you hoping to achieve using this code?

Please, let the OS do the MM...

This function, where used for ones own scripts rather than on Windows system processes, has been celebrated, but probably mostly by people who don't have much memory on their machines.

You sound like you had a bad experience with it.

Everyone at the AutoIt forums would just love to hear - on just which process it was a problem for you? - so they could know not to use it then. :D

Das Häschen benutzt Radar

Link to comment
Share on other sites

This function, where used for ones own scripts rather than on Windows system processes, has been celebrated, but probably mostly by people who don't have much memory on their machines.

You sound like you had a bad experience with it.

Everyone at the AutoIt forums would just love to hear - on just which process it was a problem for you? - so they could know not to use it then. :D

I just don"t get the purpose of this thing....

Can you tell me a use case, where it is meaningful to swap as much pages as possible of an active program?

Just let the OS do the swapping, trust me, it will do it when it needs more physical memory.

Link to comment
Share on other sites

I just don"t get the purpose of this thing....

Can you tell me a use case, where it is meaningful to swap as much pages as possible of an active program?

Just let the OS do the swapping, trust me, it will do it when it needs more physical memory.

Well Sam, you seem to know all about the internal workings of the function - you must know something in depth about DLL's or memory, or maybe you've been coding in low-level languages a lot.

I'm just a guy that used to write in older scripting languages, who moved over to AutoIt when they became obsolete.

But if you ever wrote a complete application in AutoIt that you compiled and expected would be used on a regular basis, it seems, based on what you see about the process in the Windows Task Manager, that it reliably reduces the amount of RAM your app uses by about 40 percent, which wouldn't help a guy who writes an app that uses only 5 MBs if that is all he has open on a system running 2GB's of RAM, sam.

Das Häschen benutzt Radar

Link to comment
Share on other sites

Application and process programmers used to like to do what they could to reduce the amount of memory used by, and processor load of, any program that they write, because in the old days, and still today, on some computers, people will close applications, that use too much of the machine's resources.

I started out on an 8-bit calculator about 20 years ago. With the RAM available in that calculator, it was hard pressed to compute gas-milage. :D

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

Try PM'ing whoever wrote the UDF.

Unless we paid him something - which I have no way to do electronically - we would only get a very highly technical and terse explanation concerning what applications should not use this function. That, I would quickly forget because my scripts rarely crash because of someone else's code being in them - they wimp out because my own work is lacking. :D

Das Häschen benutzt Radar

Link to comment
Share on other sites

Application and process programmers used to like to do what they could to reduce the amount of memory used by, and processor load of, any program that they write, because in the old days, and still today, on some computers, people will close applications, that use too much of the machine's resources.

You are reducing only the amount of physical memory used by the process, the amount of virtual memory remains the same.

Instead of using the RAM, the as many pages as possible are written to hard disk and then put into main memory when accessed. That sounds like a good thing, but the operating system can do such things without the intervention of the application. And it will of course swap out the unneeded parts of your program when your computer runs out of physical memory.

Maybe there are some cases where this function is useful. For example if your program changes its behavior over the time, lets say it first accesses a lot of different pages where it subsequently works on a smaller page basis. So it could be useful to write back all pages to disk, because you know that you are not going to access them in the near future.

But without knowing some details about the memory usage of the program or without even knowing the concept of virtual memory, please keep the fingers away from this function.

I started out on an 8-bit calculator about 20 years ago. With the RAM available in that calculator, it was hard pressed to compute gas-milage. :D

I guess the calculator had no concept of virtual memory, did it?

Link to comment
Share on other sites

You are reducing only the amount of physical memory used by the process, the amount of virtual memory remains the same.

Instead of using the RAM, the as many pages as possible are written to hard disk and then put into main memory when accessed. That sounds like a good thing, but the operating system can do such things without the intervention of the application. And it will of course swap out the unneeded parts of your program when your computer runs out of physical memory.

Maybe there are some cases where this function is useful. For example if your program changes its behavior over the time, lets say it first accesses a lot of different pages where it subsequently works on a smaller page basis. So it could be useful to write back all pages to disk, because you know that you are not going to access them in the near future.

But without knowing some details about the memory usage of the program or without even knowing the concept of virtual memory, please keep the fingers away from this function.

I guess the calculator had no concept of virtual memory, did it?

The calculator had a lot of things to it that I did like:

1. It wasn't accessible to nihilists in the United States Congress via the internet and Microsoft which contributes liberally to them.

2. It was quick - it didn't need no stinking swap file.

3. It was no nonsense, I could know about every operation it was undertaking - no mysterious disk activity or network activity taking command of the equipment away from me.

4. I could rest assured, anything that went wrong with its action was my fault, and not because my eternal mortal enemies are messing with my machine via a connection.

Now, the way I have it, these nice developers here at AutoIt would have complained greatly over the _ReduceMemory function if there was such a big problem with it. I have come to know the way they do things here. They are zealous over the quality of the scripting language they are building and wouldn't let anything much deleterious to get into it that would ruin its reputation. This function has been around for quite a while for everyone to evaluate how well it does in our scripts.

The bigger danger is that Windows will become obsolete because everyone will move over to Unix and Linux, because Microsoft's documentation is so cryptic, and what it is ever doing with your hard drive or you RAM is kept as some sanctified secret and made purposefully to be inaccessible to normal minds.

Now you for instance - you have basically described what is a swap file, but never said where _ReduceMemory fails. I could suspect that you used to work for Microsoft, but they had to let you go because you didn't know anything about their software, and you didn't know anything about their software because they didn't want you to.

I can assure you - the next time I have to rebuild my computer's os and do a System Recovery, it will probably be because Microsoft software crashed it, because it thought I was trying to hack their software and steal it, and not because of any UDF that was written by an independent programmer with all my same interests who probably knows machine code and C++, doesn't contribute millions of dollars to anarchists in the government of my country, and isn't subject to their intrusive mis-management and mafia-style regulations.

It is Microsoft's software that usually crashes my computer.

Das Häschen benutzt Radar

Link to comment
Share on other sites

One guy puts _ReduceMemory in his While loop, calling 10 times every second. I would use it once just before the main loop and then maybe sometimes after any major operation that might drastically change the amount of RAM my script uses.

The cautions against _ReduceMemory look like the cautions against DDT.

Das Häschen benutzt Radar

Link to comment
Share on other sites

And how do you, Sam, know that the function works by putting the process on the swap file, instead of defragging the memory it occupies or even by compressing the script as it resides in memory?

I mean no personal offense here, Sam.

But we programmers, cherish our RAM.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

The calculator had a lot of things to it that I did like:

1. It wasn't accessible to nihilists in the United States Congress via the internet and Microsoft which contributes liberally to them.

2. It was quick - it didn't need no stinking swap file.

3. It was no nonsense, I could know about every operation it was undertaking - no mysterious disk activity or network activity taking command of the equipment away from me.

4. I could rest assured, anything that went wrong with its action was my fault, and not because my eternal mortal enemies are messing with my machine via a connection.

Now, the way I have it, these nice developers here at AutoIt would have complained greatly over the _ReduceMemory function if there was such a big problem with it. I have come to know the way they do things here. They are zealous over the quality of the scripting language they are building and wouldn't let anything much deleterious to get into it that would ruin its reputation. This function has been around for quite a while for everyone to evaluate how well it does in our scripts.

The bigger danger is that Windows will become obsolete because everyone will move over to Unix and Linux, because Microsoft's documentation is so cryptic, and what it is ever doing with your hard drive or you RAM is kept as some sanctified secret and made purposefully to be inaccessible to normal minds.

Now you for instance - you have basically described what is a swap file, but never said where _ReduceMemory fails. I could suspect that you used to work for Microsoft, but they had to let you go because you didn't know anything about their software, and you didn't know anything about their software because they didn't want you to.

I can assure you - the next time I have to rebuild my computer's os and do a System Recovery, it will probably be because Microsoft software crashed it, because it thought I was trying to hack their software and steal it, and not because of any UDF that was written by an independent programmer with all my same interests who probably knows machine code and C++, doesn't contribute millions of dollars to anarchists in the government of my country, and isn't subject to their intrusive mis-management and mafia-style regulations.

It is Microsoft's software that usually crashes my computer.

What does this things have to do with Microsoft? The concept of Virtual Memory was not invented by them....

You are asking what the Risk of ReduceMemory are. Ok. Your program might run slower. Something else. No I don"t think so. But what are the benefits?

Just having a smaller number somewhere in the task manager? No.

Can you run a larger number of programs with the same amount of memory? No.

So whats the reason.

Sure, you will never have to recover your system because of that. But if that is the only benefit........

Link to comment
Share on other sites

And how do you, Sam, know that the function works by putting the process on the swap file, instead of defragging the memory it occupies or even by compressing the script as it resides in memory?

It is documented: http://msdn2.microsoft.com/en-us/library/ms682606.aspx

I mean no personal offense here, Sam.

But we programmers, cherish our RAM.

Maybe you should cherish the virtual memory consumption. No one cares about the physical memory consumption of your application!

Link to comment
Share on other sites

I guess what you are saying is that EmptyWorkingSet is the VB edition of AutoIt's _ReduceMemory. I will in no way contest this reasonable assumption. You are probably correct.

From the Microsoft documentation of PSAPI:

EmptyWorkingSet Function

Removes as many pages as possible from the working set of the specified process.

What all told, Sam, do you glean from this prosaic and exhaustive snippet of literary Americana?

Going just by your assumption that the plural noun "pages" refers to the swap file, it is talking about removing it not adding to it - or them - oh, it's nonsense.

But if were going to be so presumptive, how about this: the guy that wrote _ReduceMemory also wrote EmptyWorkingSet five years ago, let's say.

He was becoming a knowledgable programmer there, got to knowing too much to please the anti-christs that rule the United States, and when he knew that Microsoft was about to let him go for knowing too much, he wrote this code so that people would have more control over their computers because he saw what Microsoft was becoming - a right-hand man to Big Brother.

What happened next - he moved his Microsoft 401K money out of Microsoft and put it into oil in Russia, and went to work for next to nothing with the AutoIt team.

How's that for a bit of mental wizmo-presumptuousness. Without playing mind-games with anyone, but being straight-forward and succinct, not cryptic at all, there's you a mind-experiment.

But because you didn't admit to ever writing any machine code Sam, I am also left a believer - Microsoft did write most all of the software that manages the "Virtual Memory" on my machine.

Das Häschen benutzt Radar

Link to comment
Share on other sites

I guess what you are saying is that EmptyWorkingSet is the VB edition of AutoIt's _ReduceMemory. I will in no way contest this reasonable assumption. You are probably correct.

Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])

From the Microsoft documentation of PSAPI:

What all told, Sam, do you glean from this prosaic and exhaustive snippet of literary Americana?

Going just by your assumption that the plural noun "pages" refers to the swap file, it is talking about removing it not adding to it - or them - oh, it's nonsense.

No, "pages" does not mean swap file.

And "removing" means removing from physical memory, which implies it must be swapped out (which is not true in 100% of the cases, because it could already be swapped out).

So to anyone who knows about VMM, the situation should be clear.

You can read this as well: http://msdn2.microsoft.com/en-us/library/m...398(VS.85).aspx

But if were going to be so presumptive, how about this: the guy that wrote _ReduceMemory also wrote EmptyWorkingSet five years ago, let's say.

He was becoming a knowledgable programmer there, got to knowing too much to please the anti-christs that rule the United States, and when he knew that Microsoft was about to let him go for knowing too much, he wrote this code so that people would have more control over their computers because he saw what Microsoft was becoming - a right-hand man to Big Brother.

What happened next - he moved his Microsoft 401K money out of Microsoft and put it into oil in Russia, and went to work for next to nothing with the AutoIt team.

How's that for a bit of mental wizmo-presumptuousness. Without playing mind-games with anyone, but being straight-forward and succinct, not cryptic at all, there's you a mind-experiment.

But because you didn't admit to ever writing any machine code Sam, I am also left a believer - Microsoft did write most all of the software that manages the "Virtual Memory" on my machine.

I do net presume anything. I just quote what the documentation says. Of course you can say: But what if the documentation is wrong and this functions does something completely different? In that case, just consult Occams Razor.
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...