pmtolk has asked for the wisdom of the Perl Monks concerning the following question:
I modified waters code%hash; $hash{'name'}=1; $ptr=\$hash{'name'}; print $$ptr; for(1..1000){ $hash{"$_"}=$_; } print $$ptr;
$$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 allmy $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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pointer memory and dynamic memory
by Enlil (Parson) on Oct 13, 2004 at 08:05 UTC | |
|
Re: pointer memory and dynamic memory
by BrowserUk (Patriarch) on Oct 13, 2004 at 08:14 UTC | |
|
Re: pointer memory and dynamic memory
by ccn (Vicar) on Oct 13, 2004 at 08:02 UTC | |
|
Re: pointer memory and dynamic memory
by Corion (Patriarch) on Oct 13, 2004 at 08:09 UTC | |
|
Re: pointer memory and dynamic memory
by ikegami (Patriarch) on Oct 13, 2004 at 16:31 UTC | |
by water (Deacon) on Oct 14, 2004 at 02:23 UTC | |
by BrowserUk (Patriarch) on Oct 14, 2004 at 07:31 UTC | |
|
Re: pointer memory and dynamic memory
by Anonymous Monk on Oct 14, 2004 at 10:47 UTC |