"Sam Roberts" <sroberts / certicom.com> schrieb im Newsbeitrag
news:20040323190124.GB10547 / certicom.com...
> Wrote Stig Sandbeck Mathisen <ssm / fnord.no>, on Wed, Mar 24, 2004 at
01:59:30AM +0900:
> > "Robert Klemme" <bob.news / gmx.net> writes:
> > Brilliant, thank you.  I think I need to study it for a while, to see
> > exactly what it does in combination with my code, though. :)
>
> Notice that these methods don't modify YouClass.new() to return other
> than a new object, they basically implement an alternate method to
> get objects, one that may or may not create a new object.
>
> This works great, unless you don't control over the call to new.
>
> Is there a variant of this trick that would work when unmarshalling
> or un-yamling a lot of objects, where you would want there not to be
> new instances of ocbject created which are equivalent to existing ones?

AFAIK there is no hook in Marshal and Yaml that would allow to provide your
own object creation.  Someone correct me if I'm wrong here.

However, the good news is that both don't instantiate an instance multiple
times that is referenced from several places, i.e.,

str = "foo"
Marshal.load( Marshal.dump([foo,foo]))

creates only two new instances (an array and one copy of the string).

Maybe you'll have to do some post processing on what you get back in order
to replace instances.  However, that will be tricky if there are multiple
references to a single instance.  Not worth the effort I'd say.

Regards

    robert