|
NAMEIPC::Mmap::Share - Safely share structures among processes using anonymous mmap.SYNOPSISuse IPC::Mmap::Share; #create an area 10000 bytes big my $ref = IPC::Mmap::Share->new(10000); #program possibly forks later... #store the $data (can be either scalar or reference). $ref->set($data); #get the data my $data = $ref->get; DESCRIPTIONOverviewThe IPC::Mmap::Share was born out of the need to share structures among processes that come from the same ancestor. It tries to do so in a very simple and straightforward manner. Just create an IPC::Mmap::Share object, and use set to store your data and get to get it back.InternalsThis module uses the IPC::Mmap module internally to carry out its mmap tasks. When a new object is initialized, the module uses anonymous mmap (eg. it does not correspond to any real file, just some internal OS buffers) to create the area where it will be storing its data. Get and set are implemented using Storable, by freezing the variable and later thawing it from its storage. Locks are used to protect both reads from and writes to the mmaped area.MotivationThere are many excellent modules on CPAN which will happily handle all the details of interprocess communication even for complex cases. Some of these modules use shared memory and others use mmap. I needed something that uses b<anonymous> mmap and has a very simple way of operation. For many simple tasks, you may find it useful. For more complex jobs, you may want to take a look at other modules.METHODS
WARNINGIf the module fails during any of its tasks, it will try to croak.Don't try to store an undef value. Don't try to pass more than one argument to set. All other arguments will be ignored. Likewise, if you try to store an array, only the first element will get through. Instead, store a reference to the array and it will go fine. Also, please make sure that you do not try to store something bigger than the size you have initialized your object with. The module will croak if something like that occurs. If you do not know what is the serialization length of your structure, try to make a guess. The module unfortunately cannot change the size of the mmaped area after object creation. If what you are trying to do requires something more complicated than that, there are excellent CPAN modules out there which will probably suit your needs. Also, if your program is going to do LOTS of gets and sets in a short time, you may need a smarter locking mechanism. Again, take a look at these other CPAN modules. SEE ALSOYou may find these excellent modules useful: IPC::SharedCache, IPC::ShareLite, IPC::ShareableBUGSSurely there are quite a few. If you see them, report them to the proper authorities!..FUTURE WORKPerhaps IPC::Mmap::Share could conveniently subclass IPC::Mmap instead of being standalone.AUTHORIPC::Mmap::Share was written by Athanasios Douitsis <aduitsis@cpan.org>COPYRIGHTCopyright (c) 2006. Athanasios Douitsis. All rights reserved.This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See <http://www.perl.com/perl/misc/Artistic.html> POD ERRORSHey! The above document had some coding errors, which are explained below:
Visit the GSP FreeBSD Man Page Interface. |