develooper Front page | perl.perl5.porters | Postings from September 2023

Re: DAVEM TPF Grant#3 June, July, August 2023 report

Thread Previous | Thread Next
"Ruud H.G. van Tol" via perl5-porters
September 11, 2023 10:36
Re: DAVEM TPF Grant#3 June, July, August 2023 report
Message ID:

On 2023-09-08 16:27, Dave Mitchell wrote:
> Internally, perl is mainly based around Scalar Value (SV) structures,
> which hold a single value. Entities such as $x or $a[0] are all SVs. These
> SVs include a reference count (RC) field which, when it reaches zero,
> triggers the freeing of the SV. For the basics, consider the following
> code:
>      sub f {
>          my $x = ...;
>          my $y = ...;
>          return \$y;
>      }
>      my $ref = f();
> On return from the function, the SV associated with $x is freed in a
> timely manner. This is because its RC starts as 1, and is reduced to 0 on
> scope exit. Conversely, the SV bound to $y has its RC increased to 2 by a
> reference being taken to it, then back down to 1 when $y goes out of
> scope. So it lives on, accessible as $$ref. This is all good.


Unless something like:

my $y= sub { $x };


> [...] Thus items in @_ are in danger of being prematurely freed.

On @_, I remember splice() behaving different from shift(),
which could easily hurt your debugging experience.
I then refactored many splice() calls to shifts.
And never spliced @_ again.

> It is intended that eventually, PERL_RC_STACK will become the default,
> and then the only, build option.

Yes please.

-- Ruud

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About