in reply to IPC::SharedMem::stat using Class::Struct
Hello sprinter,
Welcome to the Monastery. I am not sure where you got the source code that you have posted because it is a bit different than from the CPAN IPC::SharedMem/source.
To answer your question, no the module does not have a separate pack and unpack method. See source code on the link above or sample below:
sub read { @_ == 3 or croak '$shm->read(POS, SIZE)'; my($self, $pos, $size) = @_; my $buf = ''; if (defined $self->addr) { memread($self->addr, $buf, $pos, $size) or return undef; } else { shmread($self->id, $buf, $pos, $size) or return undef; } $buf; } sub write { @_ == 4 or croak '$shm->write(STRING, POS, SIZE)'; my($self, $str, $pos, $size) = @_; if (defined $self->addr) { return memwrite($self->addr, $str, $pos, $size); } else { return shmwrite($self->id, $str, $pos, $size); } }
From the documentation IPC::SharedMem/methods, it also mentioned:
read ( POS, SIZE ) Read SIZE bytes from the shared memory segment at POS . Returns the st +ring read, or undef if there was an error. The return value becomes t +ainted. See shmread. write ( STRING, POS, SIZE ) Write SIZE bytes to the shared memory segment at POS . Returns true if + successful, or false if there is an error. See shmwrite.
Update: Forgot to add from the Synopsis of the module:
$shm->write(pack("S", 4711), 2, 2);
If you see pack documentation for S:
S An unsigned short value.
So in conclusion it is just the memory position that you read and write. I assume that the copy of the code that you post was from an earlier version but on latest version is clear that the module is using the core pack and unpack of Perl
Hope this helps, unless I did not understand your question.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: IPC::SharedMem::stat using Class::Struct (UPDATED)
by haukex (Archbishop) on Sep 29, 2017 at 06:55 UTC | |
by thanos1983 (Parson) on Sep 29, 2017 at 13:03 UTC |