1

I am debugging a program that depends on large file ~1GB. I am currently stuck in low performance PC without SSD. Each time I run the program after some edit. This 1GB has be loaded in memory which takes some time.

considering I need this 1GB file from the beginning and there is no way to load just what I need from it.

Is it possible in some way (does not have to be standard and portable) to load it just once in some place in the memory that is not destructed after exiting the program and then use it from the same place in memory each time (kind of pointer to memory chunk on the OS level) ?

I am using MSVC 2017 & Windows 10.

Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
  • 1
    Never done something like this, but I imagine you could have one dummy process keeping the file alive and then sharing it with your program after its built. It seems like boost has a library that can be used for this, see [here](http://www.boost.org/doc/libs/1_66_0/doc/html/interprocess/sharedmemorybetweenprocesses.html). – patatahooligan Jan 23 '18 at 19:22
  • 2
    As you are on windows and if you dont mind going into non portable code, [Memory Mapped Files](https://msdn.microsoft.com/en-us/library/ms810613.aspx) are excellent for this kind of use case. – Mike Vine Jan 23 '18 at 19:59
  • @Humam Helfawi, possible duplicate of https://stackoverflow.com/questions/34751873/how-to-read-huge-file-in-c – Mohammad Kanan Jan 23 '18 at 20:10

1 Answers1

1

Yes, try setting up a RAMDisk and storing this file in the RAMDisk. It will persist until you shut down your machine or delete it.

This will effectively allow your system to read from/write to this 1GB file as if it was stored on RAM - which is what you want. But it will only require a single load and a single unload.

A normal 7200RPM hard drive - what you're probably seeing by loading from HDD -> RAM upon each execution

7200RPM

A very usual SSD. As you can see, speeds are increased approximately fourfold in this benchmark.

SSD

Using a RAMDisk, in this case set up using the AMD Radeon RAMDisk software

RAMDISK

In other words, this isn't a programming solution really - it's just a workaround for your machine not having an SSD to store this large file on for read/write purposes. Your code can probably stay the same, it will just read in the file from a RAMDISK that you'll have to set up.

Hope this helps!

cptwonton
  • 500
  • 3
  • 16
  • This is counterproductive. If you have enough memory, the file cache works just as well. If you _don't_ have enough memory to hold the entire file, a file cache can hold part of a file. A RAMdisk can not. – MSalters Jan 24 '18 at 10:39