473,778 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looking for a uniform way for deep-copy

Hi,

the following class describes my actual problem:

class DeepCopy<T>
{
T val_;

public void Assign(T newVal)
{
// Here I like to perform DEEP-COPY of newVal and assign it to
val_.
}
}

I am looking for a uniform way to perform the deep-copy for both
reference and value types.

This uniform way should not use the ICloneable interface because my
program uses System.Drawing. Point at-large (and other existing
class/struct) that does not implement this interface.

Thanks a lot for any suggestion.
Marco.

Nov 17 '05 #1
5 1451
Hi,

I don;t think that it can be done, it's dependand of the type you want to
deep-copy , it's the creator of the class then one who knows how to clone
it.
The class may has private components that are important to create a clone
and that you have no access to them.

Maybe using reflection you could do something, but I don;t know if it will
work always.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<ma***********@ gmail.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Hi,

the following class describes my actual problem:

class DeepCopy<T>
{
T val_;

public void Assign(T newVal)
{
// Here I like to perform DEEP-COPY of newVal and assign it to
val_.
}
}

I am looking for a uniform way to perform the deep-copy for both
reference and value types.

This uniform way should not use the ICloneable interface because my
program uses System.Drawing. Point at-large (and other existing
class/struct) that does not implement this interface.

Thanks a lot for any suggestion.
Marco.

Nov 17 '05 #2
<ma***********@ gmail.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Hi,

the following class describes my actual problem:

class DeepCopy<T>
{
T val_;

public void Assign(T newVal)
{
// Here I like to perform DEEP-COPY of newVal and assign it to
val_.
}
}

I am looking for a uniform way to perform the deep-copy for both
reference and value types.

This uniform way should not use the ICloneable interface because my
program uses System.Drawing. Point at-large (and other existing
class/struct) that does not implement this interface.

Thanks a lot for any suggestion.
Marco.


If I understand you correctly, you are looking for a way to deep copy a
generic <T> without wanting to hardcode all of the members in the copy
routine. You can serialize the object to a memory stream then deserialize
it back into the destination. Depending on the types of the objects being
deepcopied, they may need to manually implement ISerializable.

-- Alan
Nov 17 '05 #3
By the way, you do not need to clone value types.
Point myPoint = new Point(100,150);
Point secondPoint = myPoint;
is completely OK, because actual values, not references are copied

<ma***********@ gmail.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Hi,

the following class describes my actual problem:

class DeepCopy<T>
{
T val_;

public void Assign(T newVal)
{
// Here I like to perform DEEP-COPY of newVal and assign it to
val_.
}
}

I am looking for a uniform way to perform the deep-copy for both
reference and value types.

This uniform way should not use the ICloneable interface because my
program uses System.Drawing. Point at-large (and other existing
class/struct) that does not implement this interface.

Thanks a lot for any suggestion.
Marco.

Nov 17 '05 #4
Hi,

No really, what if you have

struct A
{
int i;
object o;
}

A is a value type but you have a component of it that is a reference.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Lebesgue" <no****@spam.jp > wrote in message
news:un******** ******@tk2msftn gp13.phx.gbl...
By the way, you do not need to clone value types.
Point myPoint = new Point(100,150);
Point secondPoint = myPoint;
is completely OK, because actual values, not references are copied

<ma***********@ gmail.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Hi,

the following class describes my actual problem:

class DeepCopy<T>
{
T val_;

public void Assign(T newVal)
{
// Here I like to perform DEEP-COPY of newVal and assign it to
val_.
}
}

I am looking for a uniform way to perform the deep-copy for both
reference and value types.

This uniform way should not use the ICloneable interface because my
program uses System.Drawing. Point at-large (and other existing
class/struct) that does not implement this interface.

Thanks a lot for any suggestion.
Marco.


Nov 17 '05 #5
> No really, what if you have

struct A
{
int i;
object o;
}

A is a value type but you have a component of it that is a reference.


yes, you are right, I thought just of a System.Drawing. Point, sorry for
possible confusion
Nov 17 '05 #6

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

Similar topics

3
3340
by: Charlie Martin | last post by:
(Apologies for duplicating posts to *.misc and *.tools; Google wasn't co-operating .) Confio Software, a Boulder-based system performance tools developer, is preparing to announce our new DBFlash(TM) for Oracle version 4.6; we need beta testers before our upcoming release, so we are looking for a limited number of new sites interested in trying our new version. Qualifying sites should have:
11
3855
by: Charlie Martin Beta program | last post by:
Well, it turns out that Google automagically mangled email addresses in the last try, so here goes again. Confio Software, a Boulder-based system performance tools developer, is preparing to announce our new DBFlash(TM) for Oracle version 4.6; we need beta testers before our upcoming release, so we are looking for a limited number of new sites interested in trying our new version. Qualifying sites should have:
1
1703
by: Robert Oschler | last post by:
Is there a Javascript function, or library, that will take a URL and make it uniform/consistent? Something that will resolve all relative pathing and the current domain and protocol and return a uniform URL? Like the realpath() function in PHP? Thanks.
4
2211
by: Curious | last post by:
Hi, I am writing a class Distribution that inherits from Random class public class Distribution : System.Random { public int Uniform(int min, int max) { return this.Uniform(min, max); }
13
3115
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those sorts of clients. Mine are all small businesses whose sites will never reach those sorts of scales. I deal with businesses whose sites get maybe a few hundred visitors per day (some not even that much) and get no more than ten orders per day....
8
25481
by: kiranchahar | last post by:
Hey all, How do I generate random numbers with Uniform distribution Uniform(a,b) using C-programming? I want to generate uniform random numbers which have mean following Uniform(p,q) and also variance as Uniform(s,t)? any suggestion would be really appreciated. Thanks, Kay
25
2649
by: tooru honda | last post by:
Hi, I have read the source code of the built-in random module, random.py. After also reading Wiki article on Knuth Shuffle algorithm, I wonder if the shuffle method implemented in random.py produces results with modulo bias. The reasoning is as follows: Because the method random() only produces finitely many possible results, we get modulo bias when the number of possible results is not divisible by the size of the shuffled list.
1
1858
by: Vangati | last post by:
Plusmo is Hiring! Plusmo's mission is to provide the ultimate mobile experience for users by bringing together advanced technologies and easy to use services for mobile phones. Plusmo's innovative widget service lets users run cool "widgets" on their mobile phones. There are over 20,000 widgets and mobile mash-ups on Plusmo, most of them created and shared by end users and publishers with no coding knowledge. Join us in tackling the...
3
1386
by: henry | last post by:
Folks: I've custom-built a text-only chapter-section menu in PHP (see below). It does everything I want... But it is really quite difficult even for me to edit, add, and subtract entries. If I get run over by a truck, my successor will be very unhappy! I want to replace my "brilliant" work with code that reads the data from an easily-edited array or external tagged-text file --NOT a database-- and it
0
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10296
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7474
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2863
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.