Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Efficient shared memory - possible? how??

by Corion (Patriarch)
on Feb 20, 2012 at 12:24 UTC ( #955064=note: print w/replies, xml ) Need Help??


in reply to Efficient shared memory - possible? how??

If you are content with not having proper Perl data structures but a raw blob of memory, a good approach to sharing that data among processes (and threads) could be File::Map. This gives you a scalar region in which you can read/write shared data using substr.

If this falls into "serializing/unserializing everything all the time" territory for you, then there is little you can do about it. Perl data structures are reference counted and you will have to do some very hacky and specialized things to share a Perl data structure between processes. I can imagine that you might be able to create "shared" scalars that point to the shared region via newSV_pv(..., 0). This would tell the Perl memory manager that you want to maintain the storage space allocated to the scalar yourself. But writing to that scalar needs to be done through a special routine that makes sure the sizes still fit - you can't grow or shrink the length of the scalar for example.

Replies are listed 'Best First'.
Re^2: Efficient shared memory - possible? how??
by sundialsvc4 (Abbot) on Feb 20, 2012 at 14:19 UTC

    I think that file-mapping is an excellent suggestion because it treats the shared resource “at arm’s length” especially in the sense of avoiding the memory-scribbling that can so easily occur among supposedly well-behaved children who are sharing exactly the same playpen at the same time.   Given that bugs will inevitably occur, even due the to slightest typo, this makes things a bit easier to spot.   (e.g. as in the preceding sentence.)

    You might also seriously consider literally using a shared disk file, knowing that most if not all of the actual access will occur through a shared buffer pool that is helpfully maintained for you by the OS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://955064]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2023-01-29 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?