How to install MinWorkingSet and MaxWorkingSet in a 64-bit .NET process?

How to install MinWorkingSet and MaxWorking for a 64-bit .NET process?

ps I can set the set of MinWorkingSet and MaxWorking for a 32-bit process as follows:

[DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool SetProcessWorkingSetSize(IntPtr pProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);

[DllImport("KERNEL32.DLL", EntryPoint = "GetCurrentProcess", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern IntPtr MyGetCurrentProcess();

// In main():
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, int.MaxValue, int.MaxValue);
+5
source share
2 answers

All you have to do is change your ad like this:

[DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", 
    SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool SetProcessWorkingSetSize(IntPtr pProcess, 
    long dwMinimumWorkingSetSize, long dwMaximumWorkingSetSize);

The reason is that the function definitionSetProcessWorkingSetSize :

BOOL WINAPI SetProcessWorkingSetSize(
  _In_  HANDLE hProcess,
  _In_  SIZE_T dwMinimumWorkingSetSize,
  _In_  SIZE_T dwMaximumWorkingSetSize
);

Note that it does not use DWORD(as a 32-bit integer), but SIZE_Twhich is defined as :

The maximum number of bytes that the pointer points to. Use for count, which should cover the entire range of the pointer. This type is declared in BaseTsd.h as follows:

typedef ULONG_PTR SIZE_T;

, 64- , , long 64- . , MSDN " 64- Visual ++:

size_t, time_t ptrdiff_t - 64- 64- Windows.

, ( PITA). , EntryPoint DllImportAttribute ( ), :

[DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", 
    SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool SetProcessWorkingSetSize32(IntPtr pProcess, 
    int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);

[DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", 
    SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool SetProcessWorkingSetSize64(IntPtr pProcess, 
    long dwMinimumWorkingSetSize, long dwMaximumWorkingSetSize);

. , , - . . , .

Is64BitProcess Environment , . Is64BitOperatingSystem. , 32- 64- , , ; , 64- .

+5

, Process.CurrentProcess.MinWorkingSet.

, . , . ~ 0,7 . , , Windows. , , .

"" , , . , , reset . , .

" ", . , 8 75 . .

+5

All Articles