Setting virtual memory progrmmatically

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
 
A

Andrew McLaren

"Setting virtual memory progrmmatically" <Setting virtual memory
(e-mail address removed)> wrote ...
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).

Namaste Sudesh,

When you say "it doesn't work" ... what does GetLastError() report?

And just to be clear - are you really to Commit that memory? Or do you want
to just Reserve it?

The main reason your Commit would fail, would be if there is no backing
store available for the Virtual Memory pages. A popular form of backing
store is the paging file. It's quite possible that on your system, more of
the paging file is being utilised under Vista than it was under XP;
therefore there is no backing store available to commit the memory pages. It
isn't necessarily an error. "Virtual Memory" as seen by a process, and the
paging file on the disk, are two separate and independent concepts, although
closely related. User mode applications typically have no control over the
size of the paging file - in fact, any application which tried to set the
size of the paging file programmatically, would be a very bad design - IMHO.
But not sure that's what you're trying to do ...

Cheers
 
R

Richard Urban

Two things here.

1. When you change the size of the pagefile you have to reboot for the
change to take effect.

2. Why would you even want to do this. What you are doing is going to,
sooner or later, fragment the page file so it is no longer in one segment.

I would not allow a program that tries to do this anywhere near the
computers I maintain.

Photoshop does not do this. They create their own slush files on multiple
disks just for the use of their program. They do not screw with the pagefile
size. Your program should do the same.

--


Regards,

Richard Urban
Microsoft MVP Windows Shell/User
(For email, remove the obvious from my address)

Quote from George Ankner:
If you knew as much as you think you know,
You would realize that you don't know what you thought you knew!

"Setting virtual memory progrmmatically" <Setting virtual memory
(e-mail address removed)> wrote in message
news:[email protected]...
 
G

Guest

Hi

Thanks for your reply.
I want to just reserve it. I have replaced MEM_COMMIT by MEM_RESERVE. It is
now working fine.

Our application uses M5drvr32.exe to play .dir files. It works in Xp without
any problem.
In Windows Vista it pops up an error "This program requires at least 3MB of
free virtual memory to run."
Since we don't have control over M5drvr32.exe, I thought of changing the
virtual memory programmatically.
Is there any other way to resolve it without changing the virtual memory?

Best Regards
Sudesh
 
A

Andrew McLaren

I want to just reserve it. I have replaced MEM_COMMIT by MEM_RESERVE. It
is
now working fine.

Cool. That sounds like a more common programming idiom ... I'd really worry
about any app which needs to commit 1,000MB Virtual Memory, just to start
up!!!!
Our application uses M5drvr32.exe to play .dir files. It works in Xp
without
any problem.
In Windows Vista it pops up an error "This program requires at least 3MB
of
free virtual memory to run."
Since we don't have control over M5drvr32.exe, I thought of changing the
virtual memory programmatically.
Is there any other way to resolve it without changing the virtual memory?

Hmm, that's a Macromedia file. Where is m5drv32 coming from? Is it installed
as part of Macromedia Director? Or perhaps the Shockwave Player? How are
you running m5drv32? Are you doing a CreateProcess() in your code? What
happens if you run m5drv32 interactively, at a command line, outside your
code (ie just run it as a normal app) do you get the same error?

If you get the same error running m5drv32 interactively, then that's the
problem you need to solve first, before you even try to CreateProcess from
the EXE from code. The error message sounds suspicious to me ... whatever is
causing it is unlikley to be a simple shortage of virtual memory. Rather,
m5drv32 cannot create some runtime data structure, or similar; memory is a
furphy. I recommend you ask Adobe (as the current owners of Director and
Shockwave) or ask in the Macromedia user forums. Director MX 2004 has not
been updated for Vista; and I belive there are some compatibility issues, to
be resolved in the new version of Director to be released later this year.
But I'm just guessing ... ask Macromedia, um, I mean, Adobe:

http://www.adobe.com/cfusion/webforums/forum/index.cfm?forumid=11

BTW you understand that a user mode application should *not* try to control
a global system resource like the paging file, right? If App A wants a 400MB
paging file and AppB wants a 800MB paging file, what happens when you run
AppA and AppB at the same time? Even if it is a single user system, user
Bill might launch App A and then user Ted might do a Fast User Switching to
his own session and start AppB. Trying to control the page file (or other
global resource) from a single app is the sign of a poor quality program.
Either specify a page file size in the Installation Notes, and let the
system administrator configure the changes manually; or throw up a nice
error message saying "I need a page file of 800MB, I am quitting until you
change it" and then exit. But don't just go in and change it.

Anyway, good luck with the project!
 
G

Guest

Hi
M5drvr32.exe is not installed as apart of Macromedia Director. It is
independent.
We are using MMPOpen() is is a wrapper arround director interface.

We are getting the same error when we run M5drvr32.exe interactively.

We are using M5drvr32.exe version 5.0. Do you know where we can get the
later version.
I didn't get in net.

Regards
Sudesh
 
A

Andrew McLaren

We are getting the same error when we run M5drvr32.exe interactively.

You'll really need to work out how to make it run on its own, first. It will
never run from inside code, if you can't run it from a command line.
M5drvr32.exe is not installed as apart of Macromedia Director. It is
independent.
We are using M5drvr32.exe version 5.0. Do you know where we can get the
later version.

You might not have installed it as part of Macromedia Director; but
M5drvr32.exe is not freeware, shareware, or open source; it's the
proprietary product of Adobe Systems Incorporated (375 Park Ave, San Jose
CA, USA). You cannot deploy M5drvr32.exe in a solution, apart from by
agreeing to the terms of Adobe's licence; doing so would put your firm and
your users at legal risk. You cannot obtain or redistribute any version of
M5drvr32.exe except as part of a licensed Adobe product. Note that the
"licensed product" might be free, and even redistributable; but it will
still have a licence that requires agreement. The only people who can give
you reliable advice about this, is Adobe.

The community forums for developers using Adobe products is here:
http://www.adobe.com/devnet/

Good luck, hope you get it sorted out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top