a practical use for refaliasing

1 view
Skip to first unread message

Rainer Weikusat

unread,
Apr 6, 2021, 5:37:32 PMApr 6
to
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.
Reply all
Reply to author
Forward
0 new messages