in reply to Slow shared memory issue

You have to check the return value of sysread, like so
'memory read' => sub { sysread( MEMORY, $data, 0, $size ) // die $!; }
you'll see 'Bad file descriptor'. sysread cannot read from a filehandle opened on a string; it needs a real file descriptor. Also, you probably meant sysread( MEMORY, $data, $size, 0 ) (the third argument is the number of bytes to read and the fourth is offset - thats different from shmread).

shmread will probably still be slower, since it reads or writes the System V shared memory segment... by attaching to it, copying in/out, and detaching from it.

Replies are listed 'Best First'.
Re^2: Slow shared memory issue
by bash (Scribe) on Mar 27, 2016 at 19:00 UTC
    shmat (attach) -> memread (read) works 8x times faster

    So now I have only one question. Why IPC::Shareable do not uses benefits of shmat -> memread flow ? It uses shmread which is obviously slow...

    https://metacpan.org/source/MSOUTH/IPC-Shareable-0.61/lib/IPC/Shareable/SharedMem.pm#L97
Re^2: Slow shared memory issue
by bash (Scribe) on Mar 27, 2016 at 18:35 UTC
    You're right... missed errors checks.

    Thank you for the answer about attaching to shared segment. It's quite expensive operation. It clarify performance issue.

    Don't understand why there is no description - http://perldoc.perl.org/functions/shmread.html