473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

multiple clone and serialization problem

hi guys.
I need to clone multiple times an object and I am succesfully cloning using
the regular serialization process, using a MemoryStream. My problem is that
after cloning the object more that 7 or 10 times then my computer's memory
gets flooded and every time I call the Clone() method the processor
resources gets consumed 100% for like 30 seconds. And this problem increases
as the amount of clones are created increases. I read some other gu had the
same problem but he dindt post the answer.
Please help!

Thanks,
alex.

PS: below is the post from that guy..my problem is exactly the same.
================================================== ============================
hi there!
I implemented a Clone()-method with BinaryFormatter and MemoryStream as
shown in this Forum-Thread!
everything was fine until now. but suddenly following problem occured:

I clone quite a complex object-structure (composite-pattern, several
collections as members ...).
I need to Clone a node-object several times and add them to the parent-node.

so far, so good - everything works, BUT:
the performance to Clone (serialize & deserialize) becomes VERY slow (> 60
sec) after calling the Clone() about 10 times.
I guess its because of following:
the MemoryStream.Length increases with FACTOR 2 after EVERY Clone()-call, no
matter how big the object was to clone!!!!!
can anybody tell me, for what reason the BinaryFormatter.Serialize()-method
writes doublicated size of datas to the MemoryStream every time I call the
Clone()-method??
is there maybe something wrong with my class-structure which i want to
clone??

thanx for help!
byckler

here my Clone()-implementation:

public virtual object Clone()
{
BinaryFormatter Formatter = new BinaryFormatter(null,
new StreamingContext(StreamingContextStates.Clone));
MemoryStream stream = new MemoryStream();
Formatter.Serialize(stream,this);
stream.Position = 0;
object clonedObj = Formatter.Deserialize(stream);
stream.Close();
return clonedObj;
}
Mar 16 '06 #1
1 3795
for those interested here is the answer:
http://support.microsoft.com/default...b;en-us;890929

"Alex D." <al********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
hi guys.
I need to clone multiple times an object and I am succesfully cloning
using the regular serialization process, using a MemoryStream. My problem
is that after cloning the object more that 7 or 10 times then my
computer's memory gets flooded and every time I call the Clone() method
the processor resources gets consumed 100% for like 30 seconds. And this
problem increases as the amount of clones are created increases. I read
some other gu had the same problem but he dindt post the answer.
Please help!

Thanks,
alex.

PS: below is the post from that guy..my problem is exactly the same.
================================================== ============================
hi there!
I implemented a Clone()-method with BinaryFormatter and MemoryStream as
shown in this Forum-Thread!
everything was fine until now. but suddenly following problem occured:

I clone quite a complex object-structure (composite-pattern, several
collections as members ...).
I need to Clone a node-object several times and add them to the
parent-node.

so far, so good - everything works, BUT:
the performance to Clone (serialize & deserialize) becomes VERY slow (> 60
sec) after calling the Clone() about 10 times.
I guess its because of following:
the MemoryStream.Length increases with FACTOR 2 after EVERY Clone()-call,
no matter how big the object was to clone!!!!!
can anybody tell me, for what reason the
BinaryFormatter.Serialize()-method writes doublicated size of datas to the
MemoryStream every time I call the Clone()-method??
is there maybe something wrong with my class-structure which i want to
clone??

thanx for help!
byckler

here my Clone()-implementation:

public virtual object Clone()
{
BinaryFormatter Formatter = new BinaryFormatter(null,
new StreamingContext(StreamingContextStates.Clone));
MemoryStream stream = new MemoryStream();
Formatter.Serialize(stream,this);
stream.Position = 0;
object clonedObj = Formatter.Deserialize(stream);
stream.Close();
return clonedObj;
}

Mar 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Code4u | last post by:
My colleagues and I have been discussing techniques for implementing interfaces in C++. We're looking for a mechanism similar to COM's QueryInterface, in which a certain types of objects can be...
2
by: Hollywood | last post by:
After doing a search through google's archives of this list, I didn't see what I was looking for so here goes... Is it possible to serialize/deserialize multiple objects from a single XML file? ...
3
by: scoobydoo | last post by:
Hello, I am trying to implement ICloneable's Clone() function, using Serialization. However, my code causes an exception. I have a class derived from TreeNode called "Node1". In Node1, I...
6
by: Adam Tilghman | last post by:
Hi all, I have found that IE doesn't seem to respect the <SELECT> "multiple" attribute when set using DOM methods, although the attribute/property seems to exist and is updated properly. Those...
2
by: Rob R. Ainscough | last post by:
Is there an easy way to clone an object? What I've done in the past is write my own Clone method for each class i create and then just assign property values across objects. I was hoping VS...
0
by: =?Utf-8?B?a3Jpc2huYQ==?= | last post by:
Hi i am getting the following error while using XMLSerializer XmlSerializer ser = new XmlSerializer(typeof(Person)); ERROR: Unable to generate a temporary class (result=1). error CS0266: Cannot...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
1
tlhintoq
by: tlhintoq | last post by:
I'm pretty sure this is language independent and is going to be the same whether it's VC or C# - but my project is C# WIndows Forms just in case. Does anyone have a good handle on the sequence of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.