I am wondering about the dynamic memory allocation for arrays and hashes which
dont seem to change a pointers reference to it when they grow (I could be wrong)?
What does the pointer actually point to and what does that point to on down until we hit actual memory?
%hash;
$hash{'name'}=1;
$ptr=\$hash{'name'};
print $$ptr;
for(1..1000){
$hash{"$_"}=$_;
}
print $$ptr;
I modified waters code
my $x = {};
$x->{'named'} = 'watermelon';
print $x->{'named'} , " is quite delicious\n";
my $ref = \ $x->{'named'};
$$ref = 'cantelope';
print $x->{'named'} , " is quite delicious\n";
$x->{'named'}='mango';
print $x->{'named'} , " is quite delicious\n";
print $$ref , " is quite delicious\n";
for(1..10){
$x->{'named'}=$_;
print "$$ref $x->{'named'}\n";
}
$$ref did print mango and thus when what it pointed to
changed it pointed to the changed value.
So once a pointer points to an object
and that object gets moved in physical
memory due to (memory allocation or optimization or something) then the pointer will still
point to the correct place.
(until garbage collection or its assigned a different value, I am guessing)
thanks all
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.