473,890 Members | 5,284 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 1454
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
3346
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
3865
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
1710
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
2216
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
3129
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
25507
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
2666
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
1868
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
1392
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
11234
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
10827
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10924
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10463
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...
0
9637
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5854
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
6049
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4275
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3281
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.