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.
-
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 How to display code and escape characters
are good places to start.