I have a large matrix of values that takes up about 2GB of RAM.
I need to form a copy of this matrix, then the original can be swapped out to disk, to be loaded later. The contents of this matrix are important. Computing it initially is expensive, so you cannot easily throw it away and re-create it. It is faster to drop the matrix to disk, and then re-load it from disk, than it is to re-compute it from scratch.
Is there an easier or better way to designate a section of memory to be temporarily put on disk until next access than what I have, which is:
when the resource (2GB matrix) is not needed
- open a file
- write the file to disk
- free the memory
when the resource is needed
- open file
- read in matrix
- delete file from disk
I came across File mapping But I'm not sure this is the right thing to use