PC Review


Reply
Thread Tools Rate Thread

Setting virtual memory progrmmatically

 
 
=?Utf-8?B?U2V0dGluZyB2aXJ0dWFsIG1lbW9yeSBwcm9ncm1t
Guest
Posts: n/a
 
      23rd Jul 2007
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
 
Reply With Quote
 
 
 
 
Andrew McLaren
Guest
Posts: n/a
 
      23rd Jul 2007
"Setting virtual memory progrmmatically" <Setting virtual memory
(E-Mail 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

--
Andrew McLaren
amclar (at) optusnet dot com dot au


 
Reply With Quote
 
 
 
 
Richard Urban
Guest
Posts: n/a
 
      23rd Jul 2007
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 Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
=?Utf-8?B?U2V0dGluZyB2aXJ0dWFsIG1lbW9yeSBwcm9ncm1t
Guest
Posts: n/a
 
      24th Jul 2007
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



"Andrew McLaren" wrote:

> "Setting virtual memory progrmmatically" <Setting virtual memory
> (E-Mail 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
>
> --
> Andrew McLaren
> amclar (at) optusnet dot com dot au
>
>

 
Reply With Quote
 
Andrew McLaren
Guest
Posts: n/a
 
      24th Jul 2007
> 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/webforu...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!
--
Andrew McLaren
amclar (at) optusnet dot com dot au


 
Reply With Quote
 
=?Utf-8?B?U2V0dGluZyB2aXJ0dWFsIG1lbW9yeSBwcm9ncm1t
Guest
Posts: n/a
 
      24th Jul 2007
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
 
Reply With Quote
 
Andrew McLaren
Guest
Posts: n/a
 
      24th Jul 2007
> 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.
--
Andrew McLaren
amclar (at) optusnet dot com dot au


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding items in access combo box progrmmatically Jack Microsoft Access Form Coding 3 16th Apr 2008 10:23 PM
just upgraded memory. Do i need to change Virtual Memory setting? =?Utf-8?B?R1Q=?= Windows XP Hardware 4 9th Nov 2006 01:58 AM
memory mapped IO: device registers mapped to virtual memory or physical memory? Olumide Computer Hardware 13 9th Feb 2006 11:44 PM
virtual memory too low, virtual memory paging is being increased =?Utf-8?B?TGFkeV9TaGFyb25f?= Windows XP Performance 1 2nd Jan 2006 12:04 AM
Virtual memory low windows attempting to add to virtual memory Joe Monti Windows XP Performance 1 18th Jul 2003 06:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:17 PM.