memory allocation - implementation details??

From: Ozgun Erdogan (ozgune_at_gmail.com)
Date: 08/13/04


Date: 13 Aug 2004 11:19:05 -0700

Hi all -

So, I have a huge program with these lines added somewhere in the
program:

test_circular_ref {
  my %x = ();
  my %y = ();
  $x{child} = \%y;
  $y{parent} = \%x;
}

I'm doing shared object hijacking (with LD_PRELOAD), and am
intercepting uproot_SV(p) (I know this is a macro), and
Perl_sv_free(SV *sv).

For each variable that's not freed, I'm walking over all of its
elements, check if there are references, and if there are, I walk over
them too. If I come over to anything I've seen before, I declare a
circular reference. At that point, I print out stack traces for where
"each variable and their referees are allocated" (as I was
intercepting uproot_SV(p) too).

This works great on the first call to test_circular_ref. The problem
arises on the second call to test_circular_ref. For some reason, on
the second call, $x{child} and $y{parent} are allocated again (which
makes sense), but not the hashes themselves. This seems really weird
to me, and it feels like Perl is bypassing mallocs for arrays and
hashes.

Any ideas about what may be going on would really be appreciated.

Ozgun.



Relevant Pages

  • Re: Dynamic Hash
    ... Please read the documentation on hashes before making assumptions about how they look. ... Perl provides no alternate means of handling the issue. ... The program structures were never strings per-se, in the same sense as data ... This does not get as deeply nested as a directory tree, of course, but you should be able to see how references link together ...
    (perl.beginners)
  • Re: Creating a list of HASHes
    ... > Declare your variables in the smallest possible scope. ... This is another thing I have a tenious grasp of, hashes, ... > I would prefer to use references to hashes all around. ... time to properly formulate a question will most likely get me a proper ...
    (comp.lang.perl.misc)
  • Re: Record Hash Data Structure (Newbie)
    ... > (esp to arrays and hashes) may be I will try that after this iteration ... Kind of the opposite, by parallel hashes I mean *not* using references, ... Here, you have %point is a hash with one million entries, and each ...
    (comp.lang.perl.misc)
  • Re: using a variable to create a new variable
    ... Symbolic references are forbidden under the "use strict" ... tures, particularly hashes. ... %main::) instead of a user-defined hash. ... use another scalar variable to refer to those by name. ...
    (perl.beginners)
  • RE: pointers - references ??
    ... > Im busy reading / learning the Oreilly Advanced Perl Programming book. ... Suppose you want to pass two hashes as arguments to a subroutine. ... sub sub_hash{ ... So here references come to the rescue. ...
    (perl.beginners)