I have an application that in a certain moment has to create a temporary file and then delete it. So I'm thinking about whether it is possible to create a temporary file into memory instead of directly into disk. Then I would like to read it from memory to perform some actions and finally after doing some stuff, delete if from memory. If it is possible, how to do this in .NET Framework and C#. Also, Can performance be affected by using directly memory and not disk?
I would like to use memory directly instead of disk because I am afraid of some kind of windows permissions that does not allow to write file to some places of disk... so another doubt is: if using disk instead of memory is there a safe place to write temporary files and avoid writting permissions conflicts for windows XP,Vista,7,8? I mean, a place where is always safe to write temporary files and then delete it. Maybe, in user\Local Settings\Temp folder? is it the best place? I would like to know a safe place to save temporary files and then delete them that is working for windows versions: XP, Vista, 7, and 8.
Thanks.
You can use the MemoryStream for writing to memory instead of disk. Preformance can possibly be better using a memorystream because disks are often slower to write to. As always: profile before optimizing.
For information about the temporary folder see this thread: How to get temporary folder for current user