Re: What is an "anonymous temporary file?" (question about PerlFAQ5)



usenet@xxxxxxxxxxxxxxx wrote:
> PerlFAQ5 (v5.8.7) says:
>
> >>> How do I make a temporary file name?
>
> >>> If you don't need to know the name of the file, you can use open()
> >>> with undef in place of the file name. The open() function creates
> >>> an anonymous temporary file.
>
> >>> open my $tmp, '+>', undef or die $!;
>
> I'd like to know more about this...
>
> What is an "anonymous temporary file?" The name suggests (to me) that
> it is a "file" in memory (or virtual memory) only. Am I correct?

I would say you are not correct, but one could interpret virtual memory
to include both ram and disk in their totallity, so in that sense you would
be correct.

It is in memory to pretty much the same extent any other open file with the
same usage would be in memory.

> Or, is this an actual file on an actual filesystem? (ie, something you
> could test with -f if you knew the name?)

It is an actual file on an actual filesystem, but you inherently don't
know the name, as it doesn't have one. You could call -f on it's
filehandle, I suppose.

> If so, what filesystem?
> (how does Perl decide?)

I don't know how it decides, but it makes the wrong decision for me.
Rather than figure out how to change it's decision, I just explicitly make
a temp file, get it's handle, and then immediately unlink the file.

> I did a test on my machine - I opened a file like this, dumped a bunch
> of data to it, and then slept the script. I didn't see any indication
> of an actual disk-based temporary file in the usual places (/tmp,
> /var/tmp, $HOME, etc).

What kind of indication did you look for?

$ perl -le 'system "df -k"; open my $fh, "+>", undef or die $!; print $fh
"x"x1e6 foreach 1..5000; system "df -k"'

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda5 110610112 77740360 27251020 75% /
/dev/hda3 101107 88835 7051 93% /boot
none 1030576 0 1030576 0% /dev/shm
[rest elided]

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda5 110610112 82636052 22355328 79% /
/dev/hda3 101107 88835 7051 93% /boot
none 1030576 0 1030576 0% /dev/shm
[rest elided]

Notice that filesystem / is about 5 gig fuller than it used to be.


>
> Does Perl automatically "clean up" such temporary files when they go
> out of scope?

No, linux automatically cleans them up. (Well, if you are running on
Linux).

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.



Relevant Pages

  • AIX 5.2 maxperm & Oracle
    ... maxperm was set to 63%, ... large volumes of data IO going through the AIX filesystem cache). ... for memory with filesystem cache. ...
    (comp.unix.aix)
  • Re: [00/17] Large Blocksize Support V3
    ... to lock the filesystem block and prevent any updates to it, ... get 128 pages into a bio so all we've done churned some in memory ... I/O no faster than the current code. ... We can't use buffer heads - they can only point ...
    (Linux-Kernel)
  • Re: RFC: CONFIG_PAGE_SHIFT (aka software PAGE_SIZE)
    ... but now we waste more memory on small files.... ... allowing us to increase the fundamental block size of the filesystem. ... _whole_ kernel faster. ... If I want a inode cache, it always needs to be 8k based. ...
    (Linux-Kernel)
  • Re: [PATCH 008 of 8] md/bitmap: Change md/bitmap file handling to use bmap to file blocks.
    ... submit_bhcan and will allocate memory, ... sure the allocation won't fail. ... I don't think a_ops really provides an interface that I can use, ... interface to a filesystem. ...
    (Linux-Kernel)
  • Re: missing free space
    ... df checks with the filesystem to see how many blocks are ... What that means is that a program needs a temporary file and so it calls ... are talking about after laeving qemu running for long periods of time. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)