SetProcessWorkingSetSize does not work in compiling 64bit

时间:2015-06-15 14:56:37

标签: delphi memory

I use the following command to reduce the memory usage of my program, I'm actually testing it, only when I compile the program in 64bit this command does not work fot, no error occurs, only the memory in task managerIt does not decrease too, since in compiling 32bit works perfectly, does anyone know the detail is lacking to operate also in 64bit?

procedure TrimAppMemorySize;
var
  MainHandle : THandle;
begin
 try
  MainHandle := OpenProcess(PROCESS_ALL_ACCESS, false, GetCurrentProcessID) ;
  SetProcessWorkingSetSize(MainHandle, $FFFFFFFF, $FFFFFFFF) ;
  CloseHandle(MainHandle) ;
 except
 end;
  Application.ProcessMessages;
end;

thanks!

1 个答案:

答案 0 :(得分:3)

The documentation tells you to pass high(SIZE_T). You do this when compiling for 32 bit, but not for 64 bit. This is what you mean to write:

SetProcessWorkingSetSize(MainHandle, high(SIZE_T), high(SIZE_T));

Do note though that this code won't help performance on your machine. In fact, the only thing it can do is make the performance worse. Please remove this code.

SetProcessWorkingSetSize - Whats the catch?