Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How to share a file in memory instead of hard disk

by juo (Curate)
on Aug 27, 2004 at 02:04 UTC ( #386220=perlquestion: print w/ replies, xml ) Need Help??
juo has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I would like to know if anybody has any idea on how I can share a file into memory of Windows and how I can read this file using Perl instead of writing a file to the hard disk. Often I create some file with some parameters which then later on or read and processed but I heared that in Visual C++ you can write files to memory and don't need to write them to hard disk. Does anybody know if this is also possible in Perl and how this can be done.

Comment on How to share a file in memory instead of hard disk
Re: How to share a file in memory instead of hard disk
by davido (Archbishop) on Aug 27, 2004 at 03:47 UTC
Re: How to share a file in memory instead of hard disk
by Crian (Chaplain) on Aug 27, 2004 at 09:16 UTC
    Perhaps you could create a ram disk and then use that drive to write and read files normaly?
Re: How to share a file in memory instead of hard disk
by BrowserUk (Pope) on Aug 27, 2004 at 09:33 UTC

    Yes, this is possible. The basis of the mechanism is the CreateFileMapping API. I don't think that there is any existing module publically available to do this.

    You could use Win32::API::Prototype or related module to access the api's to do this from Perl. Perhaps the best way would be to model this behind a Tie::Handle tied interface.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
Re: How to share a file in memory instead of hard disk
by zentara (Archbishop) on Aug 27, 2004 at 14:25 UTC
    I don't know if this works on Windows, but how about using the often discussed "using a variable as a filehandle".
    #!/usr/bin/perl #Do you want to use a perl variable as if it were a file? #Previous versions of perl had IO::Stringy and IO::Scalar for that. #Perl 5.8 with PerlIO has it natively. Just use a reference to #the scalar in the filename slot of open. my $foo = ''; open FILEHANDLE, '+>', \$foo or die $!; print FILEHANDLE "Contents of File"; seek(FILEHANDLE,0,0); my @contents = <FILEHANDLE>; close FILEHANDLE or die $!; print 'From $foo: ', $foo, $/; print 'From file read: ', @contents, $/;

    I'm not really a human, but I play one on earth. flash japh

      How do you then share that memory with other processes? I don't think that's possible with the "in-memory filehandle" trick you're using.


      Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://386220]
Approved by ybiC
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-07-22 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (126 votes), past polls