I candidly agree with Anonymous. Just use a temporary-file, using something like File::Temp or Data::TemporaryBag. Then, let the filesystem’s caching mechanism do the rest of the work for you. There are actually compelling reasons to do this.
“RAM disks” were a great idea in the old days, when a program’s memory was real and disks were slow. You could manually carve out a chunk of memory and use it as a disk. There was no concept that the memory you carved-out could be paged-out. But today’s OSes do not allow you to do that. User-space memory is virtual, period.
If you simply use a temporary file, the OS knows that it is a file and may even know that it is temporary. Systems like Linux will carve out buffer pages as the least-important use of available RAM and will fill-up unused memory with it, “lazy writing” only when necessary. This works because the OS knows that this memory is being used for file-buffer purposes. Whereas, if you instead use a ram-disk, one of two things may happen and neither one of them is good: - You will seize a fixed amount of real storage from the operating system, denying it to all other uses, effectively managing itself ... as though your app actually knew how or deserved such expensive privilege.
- You will allocate a large chunk of what the OS simply sees as “your process’s virtual memory,” which it may well page-out. It does not know that you think of that memory as a file or disk.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link or
or How to display code and escape characters
are good places to start.
|