in reply to Access shared memory from Perl?

It's not that simple. You basically have to serialize your Perl data, write it to a section of memory, and unserialize it on the other side, being mindful of loxking and race conditions the whole time. This is what IPC::Shareable does.

Perhaps if you explained what you're trying to do, we could make alternative suggestions. The easiest way to share data portably is by using MLDBM::Sync.

Replies are listed 'Best First'.
Re: Re: Access shared memory from Perl?
by John M. Dlugosz (Monsignor) on Nov 08, 2003 at 05:26 UTC
    I'm writing a Windows Service (like a unix deamon; runs with nobody logged on) to communicate with the PowerLinc USB interface to the X-10 powerline protocol.

    Any user program can ask the service to send a command, such as "A1 on" to turn on lamp A1. For this, the natural mechanism is a Windows Mailslot with record-oriented mode. Many programs can open handles simultainiusly, and mine will read from the single other end and see atomic entries in the queue. Now what about the other way? only my program will read from the device, getting status reports such as "A1 is on" and commands such as "A1 on" seen on the wire issued by other control panels. Either way, now it knows A1 is on and remembers that fact. When a user program wants to "read" he doesn't care about reading from the data stream to the device; rather, he wants to know something about the current state.

    So, I want to make the current state available (read-only) to any user program. A simple way to do this is with a memory-mapped file holding an array of simple structures.

    The state info is very simple. The actual device is either on/off or maybe has a dimming level. In addition, I'll have bits to indicate whether this ID is used at all, is a real X-10 module or a macro in the program, and things like that.

    It takes something like 0.86 second to transmit one command on the powerline, and the state is simple, so the serialization isn't a problem.

    I'll post more about it in another thread, probably on CUFP.

    —John