in reply to Re: array reference
in thread array reference

In C, resizing an array invalidates existing pointers to the array.

int* a; a = (int*)malloc(...); int* b = a; a = (int*)realloc(a, ...); /* b now contains garbage */

The OP was asking if the same happens in Perl.

my @array; my $aref = \@array; push @array, ...; # Is $aref still valid? Yes.

Replies are listed 'Best First'.
Re^3: array reference
by blue_cowdawg (Monsignor) on Aug 22, 2007 at 17:07 UTC
        In C, resizing an array invalidates existing pointers to the array.

    Now that you put it that way, I understand what was being asked.

    While I can't cite which source code in core Perl it is I know I've seen how it is handled and I definitely agree with your assesment.

    Writing sample code such as you've provided solidifies it.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg