G
Guest
Hi
We have a requirement to set the virtual memory programatically in Windows
Vista. 
i.e. when we launch a application, set the virtual memory(say 2GB).

When we quit the application reset it to the original virtual memory.
I have used VirtualAllocEx().
It works only when "Automatically manage paging file size for all
drives" (This option is not there in Windows Xp) is selected in System
Preference/Performance Options. It doesn't work when "Custom size" is
selected in System Preference/
Performance Options(works fine in Windows Xp).

Please let me know how to handle this in Vista.
See the code....
dwProceeID = _getpid() ; 
 hProcess =
OpenProcess( PROCESS_ALL_ACCESS, 0, dwProceeID); 

lpVirtualMemoryAdd = VirtualAllocEx( hProcess, NULL,1024000000,
MEM_COMMIT,PAGE_READWRITE);
//getting NULL when "Custom size" is selected in Vista. 

if( lpVirtualMemoryAdd) 
 { 

VirtualQueryEx(hProcess, lpVirtualMemoryAdd, &memInfo,
sizeof(MEMORY_BASIC_INFORMATION));
VirtualFreeEx( hProcess, NULL, 0, MEM_RELEASE); 

}
BOOL bRet = CloseHandle(hProcess);
Regards 
Sudesh
We have a requirement to set the virtual memory programatically in Windows
Vista. 
i.e. when we launch a application, set the virtual memory(say 2GB).

When we quit the application reset it to the original virtual memory.
I have used VirtualAllocEx().
It works only when "Automatically manage paging file size for all
drives" (This option is not there in Windows Xp) is selected in System
Preference/Performance Options. It doesn't work when "Custom size" is
selected in System Preference/
Performance Options(works fine in Windows Xp).

Please let me know how to handle this in Vista.
See the code....
dwProceeID = _getpid() ; 
 hProcess =
OpenProcess( PROCESS_ALL_ACCESS, 0, dwProceeID); 

lpVirtualMemoryAdd = VirtualAllocEx( hProcess, NULL,1024000000,
MEM_COMMIT,PAGE_READWRITE);
//getting NULL when "Custom size" is selected in Vista. 

if( lpVirtualMemoryAdd) 
 { 

VirtualQueryEx(hProcess, lpVirtualMemoryAdd, &memInfo,
sizeof(MEMORY_BASIC_INFORMATION));
VirtualFreeEx( hProcess, NULL, 0, MEM_RELEASE); 

}
BOOL bRet = CloseHandle(hProcess);
Regards 
Sudesh