-1

There is big file. I need fast sort it. I going to process the file by part, that fit in RAM, to avoid/degrees using page file (next step: merge parts). How to use max RAM?

My solution: use WinApi file memory mapping, but I don't knew how to get part of file maximum size, but fit RAM (how to determine size)?

slou_pc
  • 9
  • 2
  • Can't really be done. Between the time where you get the maximum available RAM from the OS and the time you can claim it, some other process will probably come along and take some of it. And even after you get that maximum RAM, some other process will come along and page some of your memory out. – user4581301 Jul 14 '20 at 21:53
  • Why not just use file mapping views that don't exceed the system page size? Or at least are even multiples of the system page size? You can get the page size from `GetSystemInfo()`, and then divide the file size by the page size to determine the total number of pages needed, and then put a limit on that. You don't need to max out RAM, nor should you be trying to. – Remy Lebeau Jul 14 '20 at 22:04
  • 1
    You asked this same question [five days ago](https://stackoverflow.com/questions/62825073/allocate-the-maximum-amount-of-memory-whout-paging-in-c-under-windows). – Blastfurnace Jul 14 '20 at 22:12
  • 2
    Does this answer your question? [Allocate the maximum amount of memory whout paging in C++ under Windows](https://stackoverflow.com/questions/62825073/allocate-the-maximum-amount-of-memory-whout-paging-in-c-under-windows) – Michelle Jul 14 '20 at 22:41

1 Answers1

0

You can VirtualLock the pages you want to process. It locks in physical memory the size you need (if there is enough) swapping others to the paging file.

You can use the GlobalMemoryStatusEx function to determine how much memory your application can allocate without severely impacting other applications.

So you could map the file and lock the pages you are going to process.

Manuel
  • 2,526
  • 1
  • 13
  • 17