I understand the issues with cloning, this thread was to help me determine
there is not, which I think that it could.
"Laura T." <LT_stop@yahoo.com> wrote in message
news:u2%23$1WbBIHA.3940@TK2MSFTNGP05.phx.gbl...
>I guess the problem with generics cloning comes from the possibility that a
><T> might not be cloneable.
> Another point is the semantic mismatch of ICloneable interface.. does it
> mean shallow/deep?
>
> You can read a very good discussion here:
>
>
http://blogs.msdn.com/brada/archive/2004/05/03/125427.aspx >
> More interesting cloning subtleties:
>
>
http://blogs.msdn.com/abhinaba/archive/2006/04/19/578518.aspx >
> "Chris Mullins [MVP - C#]" <cmullins@yahoo.com> ha scritto nel messaggio
> news:OtKtfrRBIHA.3916@TK2MSFTNGP02.phx.gbl...
>> Laura's answer is dead on - Cloning & Creating a new Instance are two
>> very different things with very different use cases.
>>
>> In a number of projects I work on, we built the cornerstone of our
>> algorithms on the Prototype Pattern, which is a Clone() based
>> implementation. Cloning is great, and has a wide variety of use cases.
>>
>> In most cases though, cloning is going to be quite a bit slower than
>> creating a new instance. The code for cloning is often going to look
>> like:
>>
>> public object Clone()
>> {
>> Foo o = new Foo();
>> o.ListOfNames = this.ListOfNames;
>> o.Owner = this.Owner;
>> return o;
>> }
>>
>> This is clearly slower than just creating a new instance of Foo, as more
>> stuff is going on. As Cloning gets more complex (as it always does) it's
>> not uncommon to use Xml or binary Serialization, or even (and this is
>> bad!) do a database dip.
>>
>> Note: The above code has a subtle bug that often bites people. Both
>> copies (old and new) point to the same instance of ListOfNames & Owner.
>> In the case of the string (Owner) this may not be a problem, as strings
>> are immutable, but for many other things (Lists, Dictionaries, Datasets,
>> etc), it's a catastrophic and subtle bug. If someone goes
>> "old.ListOfNames.Clear()" both instances are affected.
>>
>> Anyone know why Microsoft never made a Generic IClonable? This always
>> seemed silly, as IClonable<T> would eliminate the cast that always
>> happens on clone. I usually end up with two methods:
>>
>> public object Clone(){}
>> public MyType CloneAsMyType() { return (MyType) Clone());}
>>
>> --
>> Chris Mullins
>>
>> "schneider" <eschneider@ooooooooo.com> wrote in message
>> news:emvRHGLBIHA.3716@TK2MSFTNGP03.phx.gbl...
>>> It seems that in some cases its quicker to clone an existing object vs
>>> creating a new object. I have not done exstensive perf test but have
>>> found cases where it helps.
>>>
>>> Anyone have any thoughts on this?
>>> Why would this be true?
>>> Is it always true? if not then why not?
>>>
>>> Thanks,
>>>
>>> Schneider
>>>
>>
>>
>