Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I've seen quite often that Perl was reusing reference addresses after garbage collection had them released before.

I was curious as to how often this address reusing happens:

#!/bin/bash for i in {1..15}; do perl -Mstrict -wle' use strict; use warnings; my %addr; my $count = 0; my $tries = 2**$ARGV[0]; for my $try (1..$tries) { my %h; for (reverse 1..1000) { $h{$_} = { value => $_}; $count++; } $addr{$_}++ for values %h; } my $reused = scalar grep $addr{$_}>1, keys %addr; my $addrs = scalar keys %addr; print "Address of reference reused $reused times, all addresses $addrs +, in $count tries";' $i done
Address of reference reused 1 times, all addresses 1999, in 2000 tries Address of reference reused 1001 times, all addresses 2999, in 4000 tr +ies Address of reference reused 2995 times, all addresses 3007, in 8000 tr +ies Address of reference reused 3011 times, all addresses 3023, in 16000 t +ries Address of reference reused 3043 times, all addresses 3055, in 32000 t +ries Address of reference reused 3107 times, all addresses 3119, in 64000 t +ries Address of reference reused 3235 times, all addresses 3247, in 128000 +tries Address of reference reused 3491 times, all addresses 3503, in 256000 +tries Address of reference reused 4003 times, all addresses 4015, in 512000 +tries Address of reference reused 5027 times, all addresses 5039, in 1024000 + tries Address of reference reused 7075 times, all addresses 7087, in 2048000 + tries Address of reference reused 11171 times, all addresses 11183, in 40960 +00 tries Address of reference reused 19363 times, all addresses 19375, in 81920 +00 tries Address of reference reused 35747 times, all addresses 35759, in 16384 +000 tries Address of reference reused 68515 times, all addresses 68527, in 32768 +000 tries

These numbers seem to be stable on my machine across multiple runs.

The bottom line is that address reusing happens all the time.


In reply to Re^2: Hashes do preserve insertion order after all by kikuchiyo
in thread Hashes do preserve insertion order after all by kikuchiyo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-20 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found