0

I'm working on an application that generates a set of bitmaps and then loads them into a form for a user to pick from.

The bitmaps are generated from a small vector library which the user can add to. The code now creates the files and then deletes them immediatelyafter use, only to have to generate them again (making the UI take seconds to load) next time the user opens the UI.

So what I'm wondering is, is it okay to leave my bitmaps in the user temp folder "forever", and regenerate them if they are not in the folder? I can't expect to be able to store the images in the application directory, due to possible permission issues, and like I said, I can't prepopulate the files since the user can add more.

Jon Fournier
  • 4,299
  • 3
  • 33
  • 43
  • This is a subjective question (open for discussion, with no real definitive answer), and really isn't a proper fit for SO's format. (The FAQ specifically mentions open-ended questions as being inappropriate here.) Sorry, but voting to close as not constructive. (And just to point out why, I totally disagree with @Jirka's answer; the `temp` folder is for just that - temporary files that should be cleaned up as soon as you're finished using them. :) – Ken White May 23 '12 at 21:57
  • I somewhat disagree with Mr White and Mr Hanika. :) .Why do they have to go in the filesystem would be my question? – Tony Hopkinson May 23 '12 at 22:03
  • I actually got around having to save the bitmaps out. – Jon Fournier May 24 '12 at 21:11
  • @TonyHopkinson - I somewhat agree with you :-) I will edit my answer to make it more obvious. – Jirka Hanika Jun 01 '12 at 19:14
  • @JirkaHanika Had to nip in to my temp folder today, 15,000 files, 70Megs. We all need to be better citizens. – Tony Hopkinson Jun 01 '12 at 20:53

1 Answers1

0

Ideally you should generate any temporary data into the RAM rather to the file system.

It is acceptable to depend on temporary files if you can make sure that your application is storing only a limited amount of such files per user. Any temporary files can be left behind on unexpected crashes/power offs no matter what your code does. You therefore need to implement a mechanism that will delete any stale files created by the same application in a previous session - presumably during its next start up.

Assuming such a safety mechanism, intentionally leaving behind temporary files when the application exits sounds like a non-standard but reasonable "cache".

Caveat: the next version of your application may need a slightly different file format, and should detect, delete and regenerate any files in a mismatched format based on some simple versioning scheme to avoid cross-build dependences.

Jirka Hanika
  • 13,301
  • 3
  • 46
  • 75