views:

186

answers:

3

I want to create a file that only resides in memory... In looking through some documentation I saw a recommendation to use a shell extension as a virtual file. Im not sure that is a workable solution but I would like to know

  1. Is it a good approach (or should I be using a ramdisk instead)
  2. Where is a good place to start to read up on it

Note: This is on the Windows platform

A: 

You don't say on which plateform you are but I'm guessing Windows. Is mmap() available? If not, I think BerkeleyDB has been ported to Windows so you should be able to use that. Win32 API may have something akin to mmap() but I don't know it.

Keltia
Unless I'm mistaken, mmap'ing a file won't load it into memory, it'll just give you a virtual memory pointer from where you can access the file. It'll only get into memory if you read from it (and into swap if the OS needs the memory)
mat
You're right about mmap(3) but that may be enough for the OP. Anyway, BDB ought to work too.
Keltia
Actually yes it is windows but the file in question is a document (word, adobe, etc).... I'm not sure how an embedded db is going to help in that regard.
A: 

As I understand, you want your program to create a "file", which resides only in memory and that you can pass on to another external program (say, Microsoft Word).

AFAIK this is not possible, short of a ramdrive. I'd suggest using a temporary folder. You will however have to come up with a strategy for deleting the file when it's not needed anymore.

Added: On second though, you might want to check out Reparse points. I'm not familiar with them myself, and they will only work for NTFS formatted disks, but perhaps they can provide you with what you want. It will be a lot of coding though.

Vilx-
A: 

If you want a file that resides only in memory, use a named pipe or something, though I question your scenario - can you go up a level and describe what you want to do?

Paul Betts
I want to open a word document but have the word document only in memory (not on disk, nor in a temp file)