Win32::MMF What's going on?

B

blaine

Hi,

I'm trying to write perl in windows environment and need to use the
package win32::mmf. Anyhow, I've got some test code below that will
write to the windows namespace but will not retrieve from it. Please
note it's just an example in production I would be writing to the ns
in one script and grabbing from the ns in another.

For some reason the second instance of mmf is not accessing the same
namespace. Any ideas?


my $mmf = Win32::MMF->new( -swapfile => "data.swp",
-namespace => "MyDataShare",
-size => 1024 * 1024 )
or die "\n\n\n\nCan not create namespace";

$mmf->setvar($tokenKey, $hashRef);
print "\n\n " . $mmf->debug();

print "\n\n<BR>--------------";

undef $mmf;
my $mmf = Win32::MMF->new( -swapfile => "data.swp",
-namespace => "MyDataShare",
-size => 1024 * 1024 ,

)
or die "\n\n\n\nCan not create namespace";

print Data::Dumper->Dump( [ $mmf->getvar($tokenKey) ] );


----
Resulting Output
=== MMF DESCRIPTOR (MMFD) =====================
| MMF size: 1048576 bytes
| No. of variables held in MMF: 1
| MMF Heap: top 1048532
| watermark 89
| bottom 20
+== HEAP STRUCTURE ============================
| blk 36: 53 bytes used
+----------------------------------------------
| blks: 1 used, 0 free, 1 total
| bytes: 53 used, 0 free, 53 total
+== VARIABLE DEFINITIONS ======================
| Var_id Address Size Type
| ccTokenIDValue 36 53 C
=== END OF REPORT =============================

=== MMF DESCRIPTOR (MMFD) =====================
| MMF size: 1048576 bytes
| No. of variables held in MMF: 0
| MMF Heap: top 0
| watermark 0
| bottom 0
+== HEAP STRUCTURE ============================
+----------------------------------------------
| blks: 0 used, 0 free, 0 total
| bytes: 0 used, 0 free, 0 total
+== VARIABLE DEFINITIONS ======================
| Var_id Address Size Type
=== END OF REPORT =============================
 
J

John W. Krahn

I'm trying to write perl in windows environment and need to use the
package win32::mmf. Anyhow, I've got some test code below that will
write to the windows namespace but will not retrieve from it. Please
note it's just an example in production I would be writing to the ns
in one script and grabbing from the ns in another.

For some reason the second instance of mmf is not accessing the same
namespace. Any ideas?


my $mmf = Win32::MMF->new( -swapfile => "data.swp",
-namespace => "MyDataShare",
-size => 1024 * 1024 )
or die "\n\n\n\nCan not create namespace";

$mmf->setvar($tokenKey, $hashRef);
print "\n\n " . $mmf->debug();

print "\n\n<BR>--------------";

undef $mmf;

perldoc Win32::MMF
[ SNIP ]
Note that there is no need to explicitly unmap the view, close the
namespace and close the swap file in object-oriented mode, the view,
namespace and swap file handles are automatically closed-off and
disposed of when the Win32::MMF object falls out of scope.

"undef $mmf" effectively closes and disposes of the MMF. Opening a new
MMF will open a new clean disk file.

my $mmf = Win32::MMF->new( -swapfile => "data.swp",
-namespace => "MyDataShare",
-size => 1024 * 1024 ,

)
or die "\n\n\n\nCan not create namespace";

print Data::Dumper->Dump( [ $mmf->getvar($tokenKey) ] );



John
 
B

blaine

I'm trying to write perl in windows environment and need to use the
package win32::mmf. Anyhow, I've got some test code below that will
write to the windows namespace but will not retrieve from it. Please
note it's just an example in production I would be writing to the ns
in one script and grabbing from the ns in another.
For some reason the second instance of mmf is not accessing the same
namespace. Any ideas?
my $mmf = Win32::MMF->new( -swapfile => "data.swp",
-namespace => "MyDataShare",
-size => 1024 * 1024 )
or die "\n\n\n\nCan not create namespace";
$mmf->setvar($tokenKey, $hashRef);
print "\n\n " . $mmf->debug();
print "\n\n<BR>--------------";
undef $mmf;

perldoc Win32::MMF
[ SNIP ]
Note that there is no need to explicitly unmap the view, close the
namespace and close the swap file in object-oriented mode, the view,
namespace and swap file handles are automatically closed-off and
disposed of when the Win32::MMF object falls out of scope.

"undef $mmf" effectively closes and disposes of the MMF. Opening a new
MMF will open a new clean disk file.
my $mmf = Win32::MMF->new( -swapfile => "data.swp",
-namespace => "MyDataShare",
-size => 1024 * 1024 ,
)
or die "\n\n\n\nCan not create namespace";
print Data::Dumper->Dump( [ $mmf->getvar($tokenKey) ] );

John



Hi John,

The above was an example of trying to use the same MMF in two
programs. So I just undef in between to show this example. However
that being said I see your point about disposing of the MMF.

How can I

1) Create a mmf in a script and save variables
2) Access the mmf in a different script ran at a different time and
get retreive the saved variables

Thanks!
Blaine
 
J

John W. Krahn

I'm trying to write perl in windows environment and need to use the
package win32::mmf. Anyhow, I've got some test code below that will
write to the windows namespace but will not retrieve from it. Please
note it's just an example in production I would be writing to the ns
in one script and grabbing from the ns in another.
For some reason the second instance of mmf is not accessing the same
namespace. Any ideas?
my $mmf = Win32::MMF->new( -swapfile => "data.swp",
-namespace => "MyDataShare",
-size => 1024 * 1024 )
or die "\n\n\n\nCan not create namespace";
$mmf->setvar($tokenKey, $hashRef);
print "\n\n " . $mmf->debug();
print "\n\n<BR>--------------";
undef $mmf;

perldoc Win32::MMF
[ SNIP ]
Note that there is no need to explicitly unmap the view, close the
namespace and close the swap file in object-oriented mode, the view,
namespace and swap file handles are automatically closed-off and
disposed of when the Win32::MMF object falls out of scope.

"undef $mmf" effectively closes and disposes of the MMF. Opening a new
MMF will open a new clean disk file.

The above was an example of trying to use the same MMF in two
programs. So I just undef in between to show this example. However
that being said I see your point about disposing of the MMF.

How can I

1) Create a mmf in a script and save variables
2) Access the mmf in a different script ran at a different time and
get retreive the saved variables

Just from reading the documentation (I don't have Windows to test on)
create the namespace file in a known location and use the -reuse option
to prevent the deletion of the file.


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top