Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why was the %Temp% folder invented?

Why will any program ever need to have to have a temporary folder for data? Can they not just use the RAM or any other temporary storage?

share|improve this question
Im struggling to write an elegant answer to this. I will let someone else do it. Think of it this way, what if you only have 2GBs of RAM and you are working on a 10GB file? You dont want the machine to page the entire time, so you need temp files/folder – Keltari Aug 29 '11 at 22:57
@Keltari: There isn't much difference between dumping 8 GB to /tmp and dumping 8 GB to a pagefile, is there? – grawity Aug 29 '11 at 22:59
The elegant answer, surely, is to point out that the disc is "other temporary storage", and is the next layer below RAM in a memory hierachy. – JdeBP Aug 30 '11 at 4:16
up vote 9 down vote accepted

The usage of "temporary" files goes back to the times when computers ran MS-DOS and had 640 kB of physical memory and no paging. Playing memory tetris with device drivers and TSRs, hopelessly trying to free up some RAM, was a common (though not exactly "favourite") past-time for PC owners.

These days, %TEMP% is still useful as a place to keep files that don't need to be permanently saved. For example, when you download a document from a website and choose "Open" instead of "Save", it still has to be saved to a file locally before being given to the program – this is the only 100%-supported method of passing data to other programs. (After all, if it was presented as a file on the website, it's simplest to save it as a file again.)

Similarly, if you open a file directly from within an archive, it is unpacked to %TEMP% first – the archiver program takes care of decompression so that other programs won't need to. Often, you can even edit the file in the program, and it will be repacked afterwards. (In comparison, if the program had to unpack the file itself, then it would have to repack it every time you save, even if that is very rarely necessary.)

share|improve this answer

Programmers and power users have been using locations called temp or test for years to store unimportant files that can be deleted when they are finished with them.

%temp% specifically relates to the Windows Temp Folder Variable, This is a per user variable (on modern systems, it defaults to %USERPROFILE%\AppData\Local\Temp). Applications can write to this folder when they have a temporary file requirement.

The biggest example of this is installers. Many installers are single files and when you see that bar that takes ages on large installations, it is usually expanding the files to the %temp% folder.

Quite often I write batch scripts that require a temporary/staging folder. They are only tiny, and I usually always end up using md temp, use it, rd temp /s. If I was distributing a script, and it involved a lot of files, it would be sensible to use a unique name in the %temp% folder (it would just be a bit more awkward to code). While the majority of people do not change the default path, there are a lot of people who do, or, server environments where you want as little as possible on the main hard drive.

As for why not use the memory, the still holds true today - it isn't large enough for everything. My first laptop had either 2 MB or 4 MB of memory (I forget), and while many programs were tiny, there were often a few that were in the 5-10 MB range (MS Office used to be about 20-30 MB for the whole suite!).

Now, the average is a lot higher (entry level machine is about 2-4 GB, and power users are 8-16 GB, power users with a bit of money 16 GB+), with a few exceptions such as scripts, the memory could really be used a lot more than it is today.

However, until the entry level machines are in the 16-32 GB Range (give it a few years!) I don't think we are going to have many advances.

%temp% is here to stay for a long while yet!

share|improve this answer
Another consideration is you could possibly be pushing other processes to the pagefile, so the OS will have to end up reading and writing to disk anyways. – surfasb Aug 30 '11 at 0:17
@Surfasb I don't really understand the exact phrasing of what you said :/ but, (I think) good point about writing the page file, however, it isn't really "directly" related to %temp%, so, trying to keep this answer simple! – William Hilsum Aug 30 '11 at 0:30
It was in reference to the question. If you writing to RAM instead of to the temp directory, you are potentially forcing the OS to push other processes to the pagefile. This is the consequence of setting up a RAMdisk for the temp directory, which usually isn't desirable. – surfasb Aug 30 '11 at 0:56
@Surfasb +2! Ok, fair enough, thanks and sorry!... I must of completely forgot that last bit of the question somewhere during writing my answer. I will try to include that. – William Hilsum Aug 30 '11 at 1:04
No blood, no foul. – surfasb Aug 30 '11 at 1:32

With software I've written, I have used temporary folders for processing aircraft CVR files. The files are generally 512 MB in size. During processing the files go through a range of formats.

  • Format A: Original proprietry data.
  • Format B: Interlaced data.
  • Format C: Four G711 files, and a CVR file containing additional data.
  • Format D: Four Wave files, and the CVR file.

I start by copying the original file to a Temp folder where all processing takes place.

I use one library to convert from format A to format C (automatically via format B). This library only takes an input file name. It decides on an output file name in the same folder. It's all out of my control.

I use a second library to convert from format C to format D.

The final directory the files are placed in is visible to the user, so I don't want them to see the files going through their transitions, or for them to see partial files, only the final output. One all processing is complete, the required files are moved to their final destination and the Temp folder is deleted.

The Temp folder hides all of this processing from the user. All they need to know is the progress percentage.

share|improve this answer
is there no way not to use temporary folders for your actions? – Pacerier Aug 30 '11 at 10:46
@Parcerier, I have no way of preventing the library from producing temporary files. I'd have to ask the library designer to change their library to suit my specific case, and they're not going to spend time or money on that. – Hand-E-Food Aug 30 '11 at 22:59
Using files is a more responsible way to manage large amounts of data. Say this process wanted to use 750Mb of memory, and I had 1Gb on memory. If a user decided to run other applications while this data processsing went on, then Windows would continuously be swapping both the application and the background process in and out of virtual memory, resulting in much poorer performance of both processes. – Hand-E-Food Aug 30 '11 at 23:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .