• a practical use for refaliasing

    From Rainer Weikusat@21:1/5 to All on Tue Apr 6 22:37:26 2021
    At the implementation level, Perl arrays are C arrays of SV * plus some metadata. This implies that it's theoretically possible for two Perl
    arrays to have a pointer to the same SV in a slot. Thanks to the
    (unfortunately experimental) 'refaliasing' feature, it's now possible to
    use this from Perl:

    -----------
    use feature 'refaliasing';

    my (@a, @b);

    use Devel::Peek;

    @a = qw(a b c d e);

    \$b[1] = \$a[0]; # $a[0] and $b[1] are now the same SV

    Dump($a[0]);
    Dump($b[1]);

    $b[1] = 15;

    Dump($a[0]);
    Dump($b[1]);
    ------------

    NB: The actual use-case behind this contrived example are two objects representing a non-blocking read and a non-blocking write operation
    sharing a socket stored in a third object containing them.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)