[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Keeping a program loaded in RAM only.

Posted on 2000-02-17
8
Medium Priority
?
226 Views
Last Modified: 2010-04-02
Using VC++ 6 on WinNT40.
Is there a way to:
a) Load an application into RAM only and "lock" it so that it never gets pagged to disk?

b) Alloc RAM only?  i.e. if there is not enough RAM to load the entire program into, fail to alloc it.
0
Comment
Question by:snifong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Expert Comment

by:GlennDean
ID: 2533844
snifong:
  I know for device driver code you can tell NT to lock it's code in memory (but that's because the driver executes in a kernel context).  BUT, for any 'ol application I seriously doubt you could do that.
   Glenn
0
 
LVL 3

Accepted Solution

by:
ufolk123 earned 200 total points
ID: 2533861
a) Following function does that.
The VirtualLock Win32  function locks the specified region of the process’s virtual address space into memory, ensuring that subsequent access to the region will not incur a page fault.

BOOL VirtualLock( LPVOID lpAddress,
 // address of first byte of range to lock
 DWORD dwSize
 // number of bytes in range to lock );
 
b) VirtualLock() will give you an error if it can not allocate that much required for your address range from OS but definitely this can not be done at load time .

ufolk123
0
 
LVL 3

Expert Comment

by:GlennDean
ID: 2533891
ufolk123:
  I agree that VirtualLock guarantees that the specified pages will be in RAM when any thread from the app executes.  BUT this does NOT mean the pages are always in memory!  VirtualLock stores the pages into the app's Working Set, i.e. those pages the app requires to be in memory when any thread from the app executes.  BUT, if another process executes, NT is free to page out any page in the app's Working Set.
   Glenn  
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:ufolk123
ID: 2534412
Sorry, Yeh I missed that point.
But  i do not feel applicaiton can do more than that from win32 layer.
Yes it is not possible for user app to control RAM that way.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2534596
>> VirtualLock guarantees that the specified pages
>>  will be in RAM when any thread from the app
>> executes.  BUT this does NOT mean the pages
>> are always in memory!
Are you sure about that?  Where did you find that?  That makes the function nearly useless.  (You are practicaly given that guarantee anyways.)

snifong, why do you want to do this?  Most people try this in order to speed up performance.  But there is a flaw in their thinking so they usually end up makeing performance worse!
0
 
LVL 1

Author Comment

by:snifong
ID: 2534677
The company that I am with is trying to figure out if they want to go to a web based configuration tool to configure firmware settings for Natural Microsystems boards.  Enable for this to happen there must be a web server on the box in order to connect.  The app we are configuring needs to be as close to realtime as possible.  We want to make sure when paging happens that it is the server and not the other app.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2534991
Locking memory can reduce performance, not improve it.  The system swaps memory based on its frequency of use.  So if you use the memory frequenly, it is not likely to be swapped out, if you use it less frequently it might be.  If you lock the memory it won't be.  Is that faster?  Well, if the OS needs to swap memory out it will, if it can't swap out yout memory it will swap out other memory.  This means it may swap out more frequently used memory and leave your less frequently used memory swapped in.  Do you think that will increase performance?  
0
 
LVL 1

Author Comment

by:snifong
ID: 2535061
GlennDean, you were right. Thanks.
nietod, Thanks as always for your comments.
ufolk123, Thanks for the push in the right direction.

Article ID: Q94996  
SUMMARY
VirtualLock() causes pages to be locked into an application's working set (virtual memory); it does not lock them absolutely into physical memory. VirtualLock() essentially means "this page is always part of the process's working set."

The system is free to swap out any virtually locked pages if it swaps out the whole process. And when the system swaps the process back in, the virtually locked pages (similar to any virtual pages) may end up residing in different real pages.

For part a) there is no way to do it 100%.  For b) VirtualLock() will return false if the pages cannot be locked.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question