Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a file in memory?

Tags:

I have see this term branded around but I don't really understand how you open a file in memory.

I have the files written to disk in a temp location but this needs cleaning when a certain form closes and I can't do it when it's open. It's a must that this folder gets emptied. I was wondering if I opened files in memory instead whether it would make a difference?

like image 651
rik Avatar asked Jun 03 '11 12:06

rik


People also ask

How do I open a memory file?

To open a memory file, use the mmioOpen function with the szFilename parameter set to NULL and the MMIO_READWRITE flag set in the dwOpenFlags parameter.

Does opening a file load it into memory?

No, it doesn't load the entire file into memory. "Opens a file" returns a handle to you allowing you to read from or write to a file.

What is an in memory file?

The distinguishing characteristic of memory files is that they exist solely in memory, occupying their own memory space separate from the data and index caches. Memory files satisfy the need for the creation and manipulation of temporary data or index files that are always memory resident and never touch disk.


1 Answers

MemoryStream inMemoryCopy = new MemoryStream(); using (FileStream fs = File.OpenRead(path)) {   fs.CopyTo(inMemoryCopy); } // Now you can delete the file at 'path' and still have an in memory copy 
like image 79
Teoman Soygul Avatar answered Sep 29 '22 15:09

Teoman Soygul