mimicking a file in memory
grante at visi.com
Tue Nov 20 23:06:34 CET 2007
On 2007-11-20, Jarek Zgoda <jzgoda at o2.usun.pl> wrote:
>> Here is my dilemma: I don't want to copy the files into a
>> local directory for mutagen's sake, only to have to remove
>> them afterward. Instead, I'd like to load the files into
>> memory and still be able to hand the built-in "file" function
>> a filename to access the file in memory.
>> Any ideas on how to do this?
By "memory" I presume you mean virtual memory? RAM with
disk-blocks as backing store? On any real OS, tempfiles are
just RAM with disk-blocks as backing store.
Sound similar? The only difference is the API used to access
the bytes. You want a file-I/O API, so you can either use the
extensively tested and and highly optimized filesystem code in
the OS to make disk-backed-RAM look like a file, or you can try
to write Python code that does the same thing.
Which do you think is going to work faster/better?
[The kernel is generally better at knowing what needs to be in
RAM than you are -- let it do its job.]
IOW: just use a temp file. Life will be simple. The bytes
probably won't ever hit the platters (if they do, then that
means they would have the other way too).
Grant Edwards grante Yow! It's a hole all the
at way to downtown Burbank!
More information about the Python-list