On Wed, 3 Sep 2003, Gordon Henriksen wrote:

> What's a dump stream actually going to look like? E.g.,

> Fine and good. But dump must handle object graphs, which can be
> recursive or self-referential or whatnot:
> 
>     $a = { b => undef };
>     $b = { a => $a    };
>     $a->{b} = $b;
>     print dump($a);

Something like:

  PMC(s) => PMC0x0000001
    [
      type(s) => perlhash
      flags(i) => 0x45626657
      [
        b(p) => PMC0x0000002
      ]
    ]
  PMC(s) => PMC0x0000002
    [
      type(s) => perlhash
      flags(i) => 0x563724
      [
        a(p) => PMC0x0000001
      ]
    ]

When a PMC is dumped, any PMC it references is always noted with a label
(We never dump the actual referred-to PMC at this point), and those
referenced PMCs are dumped out later in the stream.

> A seen hash is also threadsafe, can be interrupted by DoD, and is safe
> for recursion. (By "threadsafe," I mean that unchanged data structures
> can be safely serialized from multiple threads without ill effect or
> possibility of deadlock.)

While a seen hash is DOD-interruptable (which, admittedly, the scheme I'm
preferring isn't, or is with a *lot* of care) it's also slower and
requires a lot more resources when running. What I'd prefer to do doesn't 
require any headers during its run, nor additional memory past the memory 
(which we can safely GC) used to hold the serialized data.

Note that a seen hash isn't particularly threadsafe here, at least not in 
any useful way, since we have to make sure the structure we're traversing 
doesn't change during traversal or any threadsafety we put in is useless 
since we're potentially dumping corrupt data.

                                        Dan

Reply via email to