I have just uploaded the Win32::MMF module to PAUSE, which will (hopefully) appear in CPAN soon. Big thanks to
PodMaster for picking the namespace for me. And thanks to NetWallah for testing and ideas on OO :-)
This module is primarily designed for inter-process and intra-process communication under Windows, using the Windows own native memory mapped file facility - the backbone of Windows virtual memory.
The core of the module is written in XS for performance. This is the first release of the module so the functionalities are limited. The following is a demo on how to do intra/inter-process communication using the module. Any suggestions and beta-testing are greatly welcome, especially on locking. :-)
use strict;
use warnings;
use Win32::MMF;
use Data::Dumper;
use CGI; # for testing of inter-process object transportation
# fork a process
defined(my $pid = fork()) or die "Can not fork a child process!";
if ($pid) {
my $ns1 = Win32::MMF->new ( -namespace => "My.data1" );
my $ns2 = Win32::MMF->new ( -namespace => "My.data2" );
my $cgi = new CGI;
my $data = {a=>[1,2,3], b=>4, c=>"A\0B\0C\0"};
$ns1->write($data); # autolocking by default
$ns2->write($cgi);
print "--- Sent ---\n";
print Dumper($data), "\n";
print Dumper($cgi), "\n";
sleep(1);
} else {
# in child
sleep(1);
my $ns1 = Win32::MMF->new ( -namespace => "My.data1",
-nocreate => 1 )
or die "Namespace does not exist!";
my $ns2 = Win32::MMF->new ( -namespace => "My.data2",
-nocreate => 1 )
or die "Namespace does not exist!";
my $data = $ns1->read();
my $cgi = $ns2->read();
print "--- Received ---\n";
print Dumper($data), "\n";
print Dumper($cgi), "\n";
print "--- Use Received Object ---\n";
# use the object from another process :-)
print $cgi->header(),
$cgi->start_html(), "\n",
$cgi->end_html(), "\n";
}
PS: Package source code is on CPAN.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.