Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

How I can adjust Windows XP,so my program always stay in memory and NOT move to swap file?

Hellow Experts !
I has some dificult qustions – and need of your help !

I am writing software that assists to copy/move of real big files by fast 1 000 MB LAN. The size of files is larger – form 50 MB to 10 GB ! So after I copy about 1-2 GB Windows sets all RAM for copy process and kick up RAM, used in my software. In result – my application needs of some seconds in range 8-15 to become accessible :(

I have tried with many RAM – 1 GB –it improves response time, but not good enough. So I think that solutions must be in software.

I use Windows XP Pro (with SP2) or Windows 2000 (with SP4). I can NOT use Windows 2003 server.  To copy files my application use ActiveX – Microsoft  file system object.

So how can I order to windows to NOT move to swap file RAM, used form my software? May be some API that I can use? I use Visual Basic 6.0 with SP5, but can work and with C++.

I will be thankful to any help!
  • 2
  • 2
1 Solution
I'm not sure that you can (or should) do this. The Swap file is there for a reason, and other applications might not like having access to it removed. Plus, in terms of windows programming, access to memory is totally abstracted from you (protected mode) - if you as for an array of 10,000 integers to be allocated, you can never tell if that's all in RAM, or in the swap file, etc. Windows automatically chooses for you.

You could limit the size of the swap file in Windows to try to force Windows to use physical memory, but that's putting a lot of pressure on the system, again if other applications (including Windows) need to use it  or RAM you would actually see degraded performance, instead of an increase.

Are you sure you could not solve your problem by looking at the copying routine that is being used - for example if fix the amount of memory that is usable by the file copy process, that is to say, decide that you will copy the files in 128MB chunks. That way if you are running 4 of these processes side by side, the most memory in use at any one point is 512MB + overhead for code, but it won't increase because you don't let it.

If you opted for this method you could stop using the FSO and write your own binary file copying utility, which would give you total control over how much memory is being used to copy the files, even with multiple processes running the same code.
(By writing your own binary copying utility I mean that you would write your own cut-down FSO which you have more control over, which would allocate buffers dynamically in memory and read a chunk from the source file into the buffer, send the chunk down the wire, release the chunk, read another chunk...and so on.
The only downside is that you'd need a program on the other end of the wire to accept these chunks, but I still reckon this is the most memory friendly way if you have multiple copies going on.)

dvplayltdAuthor Commented:
Thank you fatalXception.

For me copy process is NOT time critical. I prefer to delay it, than windows kick up RAM, used for my application.
It is a good idea to read and write a chink of file. In that way I can control RAM byffer and speed of copy, used to copy process. Idea is good, but I must write many code for this. I will wait some days to see if their some APIs or registry changes.
What buffer you suggest for WinXP Pro for :
   * PC with 512 RAM
   * PC with 1 GB RAM ?

I do NOT want to control memory - I just want my application to stay always in memory. For example - I can assing to my software HIGH priority (for CPU). Why I can NOT make same with RAM ? My software do NOT use many RAM so performance will be unaffected ram.
The reason you can't tell Windows "i want to use X amount of physical RAM and not Swap file" is just because of the way it is designed - I suppose they wanted to makre sure that no one application could hog all of the memory and force the others to live off the (slower) swap file.

In terms of buffer sizes, the best way to decide how much you can afford to allocate at any one time it to check the normal memory usage of your system, and see how much RAm is free furing normal usage.
Then decide hw many processes you want to run, leave 50MB of RAM free for other apps/your app , and divide what's left by the buffer count, this is the biggest size you can safely use per buffer without forcing a swap file access.

e.g if you have 300 MB free, and want 4 buffers
(300-50) / 4 = 62.5 so you could stretch this to 64MB/buffer and have enough space to run your app as well., without forcing swap file access

But remember, if in the meantime another app starts up, and is using a lot of RAM, you may end up being forced into the swap file sometimes.
Detect how much memory is available and how much ram in total and create a ram drive taking into consideration the amount of ram so that you dont over use RAM. Then you can use that. I have seen some questions on here which are most likely now PAQ's with regards to RAM drives and how to use them. These are in the visual basic TA so have a search around on here for them :) Not sure if that is of any use :-S Just thought I would stick my 2 cents in though :)
dvplayltdAuthor Commented:
I do NOT think that RAM drive will slow thinks.

I read more - the problem is that "File Cache Management" give all memory to file cache and kick up many of RAM used in software to swap. Then when you need of software - it takes some seconds to move it RAM from swap to memory.

I think that control (limit) of RAM, used form File Cache Management is the rigth way. However - I can NOT find how to do it.

Are anyone know some registry settings or other that can I use ?


Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now