views:

105

answers:

2

I am going to be running an app(s) that require about 200MB of market data each time it runs. This is trivial amount of data to store in memory these days, so for speed thats what i want to do.

Over the course of a days session I will probably run, re-run, re-write and re-run etc etc one or more applications over and over.

SO, the question is how to hold the data in memory all day such that even if the app crashes I do not have to reload the data by opening the data file on disk and re-loading the data?

My initial idea is to write a data server app that does nothing more than read the data into shared memory so that it is available for use. If I do that I guess I could use memory mapping for the IPC by calling

CreateFile()

CreateFileMapping()

MapViewOfFile()

Is there a better IPC/approach?

+1  A: 

Just memory map the data file. Unless your computer is low on memory, the file will stay in file cache even when the program exits. The next time it starts up, access will be fast.

If your in-memory data is different from the on-disk data, just use two files. On restart, check a timestamp and a file revision written into the memory file to compare to the disk file and that way your program will know which one has the most recent data.

Zan Lynx
If I understand you correctly, you are suggesting a single application can leave the data in memory when it exits?Not sure how this would work since the application calls UnmapViewOfFile pData CloseHandle hFileMapping CloseHandle hSys
Mike Trader
@Mike - I'm not a Windows guy so I'm not sure if its memory mapping facility has some option for persistence beyond the end of your program. What it no doubt does have is some kind of reference count on mem-mapped files. So write a little program that does nothing but load the file at the beginning of the day. When you run your real app the OS should just attach to what is already in memory when you do your file mapping.
Duck
@Mike - I am saying that the OS will keep the unmapped file data in RAM unless it needs that memory for something else.
Zan Lynx
+1  A: 

If you have enough memory and nothing else asks for memory, that might reduce your startup time. To guarantee access to the memory, you probably want to have a memory mapped file in named shared memory, as described here. You can have a simple program create the share and manage it so you can guarantee it remains in memory.

Charlie Martin