Win32::MMF What's going on?

Discussion in 'Perl Misc' started by blaine@worldweb.com, Feb 12, 2008.

  1. Guest

    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 =============================
     
    , Feb 12, 2008
    #1
    1. Advertising

  2. 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
     
    John W. Krahn, Feb 13, 2008
    #2
    1. Advertising

  3. Guest

    On Feb 13, 12:10 am, "John W. Krahn" <> wrote:
    > 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
     
    , Feb 13, 2008
    #3
  4. wrote:
    >
    > On Feb 13, 12:10 am, "John W. Krahn" <> wrote:
    >>
    >> 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
     
    John W. Krahn, Feb 13, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Lyman
    Replies:
    0
    Views:
    702
    Alex Lyman
    Mar 7, 2004
  2. Java and Swing
    Replies:
    1
    Views:
    700
    Chris Lambacher
    Oct 24, 2005
  3. Tim Golden
    Replies:
    0
    Views:
    458
    Tim Golden
    Oct 21, 2005
  4. rcmn
    Replies:
    1
    Views:
    364
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Nov 6, 2006
  5. Michael Edmonson

    Win32::SAPI4 question (Win32 events and Perl)

    Michael Edmonson, Feb 28, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    199
    Michael Edmonson
    Feb 28, 2004
Loading...

Share This Page