Bagarre has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, This is directed to the PerlMonks that have C background as well

I have a program that uses Tie::Win32MemMap to share data ( A Hash ) between several other perl programs we use. Another program is being written (actualy, it's a perl prorgam I wrote that is being ported to C ) and it needs to be able to access the shared memory as well.

He's able to access the Memory Space but, can't make heads or tails of the data (hash structure) there. He's going to have to be able to read and write to the memory space just like the perl programs do.

How do you go about this? It really is a C question but, since the memory space was created with perl, I thought I'd ask here.

Thanks much for any help.

Entities should not be multiplied unnecessarily.

Replies are listed 'Best First'.
Re: Win32::MemMap and C++
by Corion (Patriarch) on Feb 19, 2004 at 19:18 UTC

    I believe you should be able to steal some code from Rogers Win32::MMF, which implements variable sharing through Win32 Memory Mapped Files, and it is mostly transparent on the Perl side.

    For writing to a shared hash, I believe that you will face some deadlock issues and that you will have to embed some of Perl into the new C program tohave the same hashing algorithm etc., at least if you want to create new keys.

      Thanks Corion for mentioning my module. :-)

      The latest version, Win32::MMF version 0.09c has been uploaded to CPAN, this release is stable, after extensive testing done by xiper (big thanks) who has discoverred several bugs with shared memory locking, all the known problems should have been fixed.

Re: Win32::MemMap and C++
by BrowserUk (Patriarch) on Feb 19, 2004 at 19:15 UTC

    For the best exploration of Perl's hash (and other) data structures I have seen, see Gisle Aas' PerlGuts Illustrated. Then perlguts, perlxstut, perlxs et al.

    Another, possibly easier, method would be to embed a perl interpreter into the C-program and use that to interface to the hash.

    Or, perhaps you could stick with the existing Perl script, but use Inline::C (or XS) to speed up the heavy processing, and leave interfacing to the shared hash in Perl.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Timing (and a little luck) are everything!