NAME

Win32::MMF - Win32 Memory Mapped File (MMF) Support for Perl

SYNOPSIS

use Win32::MMF;

$debugmode = GetDebugMode();		# 0 - off, 1 - on
SetDebugMode($debugmode);

$fh = CreateFile($filename);		# Create new swap file
$fh = OpenFile($filename);		# Open existing swap file
CloseHandle($fh);				    # Close openned swap file handle

$ns = CreateFileMapping($fh, $filesize, $namespace);
$ns = OpenFileMapping($namespace);	# Use existing namespace
CloseHandle($ns);				        # Close openned namespace

$var = MapViewOfFile($ns, $offset, $size)	# Create a view inside the namespace
UnmapViewOfFile($var);			        # Delete the view

Poke($var, $str, length($str));	# Store a string into view
$str = Peek($var);			    # Retrieve a string from the view

PokeIV($var, $i);				    # Store a number(long) into view
$i = PeekIV($var);			    # Retrieve a number from the view

# High-level Namespace Functions

# claim a swapfile to use as namespace
($swp, $ns) = ClaimNamespace($swapfile, $namespace [, $size]);

ReleaseNamespace($swp, $namespace);

$ns = UseNamespace($namespace);  # use existing namespace

ABSTRACT

This module provides Windows' native Memory Mapped File Service for inter-process or intra-process communication under Windows. The module is written in XS and is currently supported only under Windows NT/2000/XP.

The current version of Win32::MMF is available on CPAN at:

http://search.cpan.org/search?query=Win32::MMF

CREDITS

All the credits go to my beloved wife Jenny and son Albert, and I love them forever.

DESCRIPTION

use strict;
use warnings;
use Win32::MMF;

# define a swap file
my $swapfile = undef;
my $namespace = 'MyMMF.MyString';

# fork a process
defined(my $pid = fork()) or die "Can not fork a child process!";

if ($pid) {
    # in parent

    # claim a namespace of default 64K size
    my ($swap, $ns) = ClaimNamespace($swapfile, $namespace);

    # create a view of 100 bytes inside the namespace
    my $view = MapViewOfFile($ns, 0, 100);

    my $str = "This is a test";

    print "Write: $str\n";
    Poke($view, $str, length($str));

    sleep(3);

    UnmapViewOfFile($view);
    ReleaseNamespace($swap, $ns);
} else {
    # in child

    sleep(1);   # wait for parent to finish writing

    # use an existing namespace
    my $ns = UseNamespace($namespace) or die "Namespace $namespace not found";

    # create a view of 100 bytes inside the namespace
    my $view = MapViewOfFile($ns, 0, 100);

    my $str = Peek($view);
    print "Read: $str\n";

    UnmapViewOfFile($view);
    ReleaseNamespace(undef, $ns);
}

AUTHOR

Roger Lee <roger@cpan.org>