views:

168

answers:

3

I am writing an app that may have in its memory quite a bit of data. I dont want to write the data to disk ad hoc because there may be more data to write, I could append the data, but I dont want to run into any file corruption issues.

Are there any good tutorials or trusted methods describing how a windows program typically makes use of temp files? I want to be able to recover the data on a disaster such as a reboot or loss of power.

A: 

Typically applications will write their temporary files to %TEMP% if they just need temporary non-recoverable file access, however, you will probably be better off writing them to the Users directory in your own folder you have created there. This folder is typically going to be the same spot that the User would choose when the Save dialog pops up. An important point is to give the files a unique naming scheme and file extension to differentiate them from user-created files (or even put them in their own hidden directory).

hova
also:1. if you use the users directory make sure your uninstaller asks to delete the temp files. otherwise use the regular windows temp folder because there are already mechanisms to clean up that location.2. for C#, use System.IO.Path.GetTempPath()
djangofan
And please, don't write somewhere within %UserProfile% but rather within %LocalAppData%. I hate it when programs think my profile belongs to them.
Joey
I hear you all loud and clear ;0) Thank you for the responses
Matt1776
A: 

this sounds like several of the listed Appropriate Uses for SQLite:

  • Application File Format
  • Replacement for ad hoc disk files
  • Internal or temporary databases
Javier
Thank you! That may be a way to go
Matt1776
A: 

You didn't mention the language being used, but memory mapped files could be an option if you are using C or C++. They can help reduce the memory footprint and increase the performance of your application considerably.

This may help determine if this is for you.

http://msdn.microsoft.com/en-us/library/ms810613.aspx

It appears memory mapped file support is coming to a .NET near you.

http://blogs.msdn.com/bclteam/archive/2009/05/22/what-s-new-in-the-bcl-in-net-4-beta-1-justin-van-patten.aspx

Michael McCloskey
Thank you too :) I am using python, but if the gain is significant enough or if i need it, i will look into a possible ctypes extension
Matt1776