Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Win32::MMF What's going on? (http://www.velocityreviews.com/forums/t906392-win32-mmf-whats-going-on.html)

blaine@worldweb.com 02-12-2008 11:28 PM

Win32::MMF What's going on?
 
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 =============================





John W. Krahn 02-13-2008 07:10 AM

Re: Win32::MMF What's going on?
 
blaine@worldweb.com wrote:
>
> 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
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

blaine@worldweb.com 02-13-2008 03:05 PM

Re: Win32::MMF What's going on?
 
On Feb 13, 12:10 am, "John W. Krahn" <some...@example.com> wrote:
> bla...@worldweb.com wrote:
>
> > 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
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall




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

John W. Krahn 02-13-2008 03:24 PM

Re: Win32::MMF What's going on?
 
blaine@worldweb.com wrote:
>
> On Feb 13, 12:10 am, "John W. Krahn" <some...@example.com> wrote:
>>
>> bla...@worldweb.com wrote:
>>
>>> 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
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall


All times are GMT. The time now is 06:31 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.