473,396 Members | 1,975 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,396 software developers and data experts.

Copying objects

I am using vb .net and need to copy entire structures and
objects, not just make new references. What is the
best way to copy the values in the objects without making
my own copy subroutine that copies each element
individually.

It is my understanding that If I just
set obj A = B then A only contains a reference to
B and doesn't actually make a new copy. I have
looked in the help files extensively and
haven't found a definitive answer. It seems to me
that I have to deserialize the original object
somehow and then serialize it to the new object.
Any help would be appreciated.
Jul 21 '05 #1
2 1565
Look into serializing your objects and passing them around. Check the help
file (ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconserialization.htm)

"Brook Young" <br********@ameritech.net> wrote in message
news:07****************************@phx.gbl...
I am using vb .net and need to copy entire structures and
objects, not just make new references. What is the
best way to copy the values in the objects without making
my own copy subroutine that copies each element
individually.

It is my understanding that If I just
set obj A = B then A only contains a reference to
B and doesn't actually make a new copy. I have
looked in the help files extensively and
haven't found a definitive answer. It seems to me
that I have to deserialize the original object
somehow and then serialize it to the new object.
Any help would be appreciated.

Jul 21 '05 #2
The standard way is to implement ICloneable. Usually you do have to copy the
elements manually.

An alternative way is to write some routine which uses reflection to follow
object references, but note that this would be very expensive for general
use. It would also be wasteful (for instance, there is no need to clone
strings themselves, only the reference need be cloned).
"Brook Young" <br********@ameritech.net> wrote in message
news:07****************************@phx.gbl...
I am using vb .net and need to copy entire structures and
objects, not just make new references. What is the
best way to copy the values in the objects without making
my own copy subroutine that copies each element
individually.

It is my understanding that If I just
set obj A = B then A only contains a reference to
B and doesn't actually make a new copy. I have
looked in the help files extensively and
haven't found a definitive answer. It seems to me
that I have to deserialize the original object
somehow and then serialize it to the new object.
Any help would be appreciated.

Jul 21 '05 #3

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

Similar topics

5
by: Thomas Lotze | last post by:
Hi, another question: What's the most efficient way of copying data between two file-like objects? f1.write(f2.read()) doesn't seem to me as efficient as it might be, as a string containing...
3
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore...
13
by: franky.backeljauw | last post by:
Hello, following my question on "std::copy versus pointer copy versus member copy", I had some doubts on the function memcpy, as was used by tom_usenet in his reply. - Is this a c++ standard...
6
by: ziwu | last post by:
std::copy() is a function from C++ library. Is memcpy() a function from C library, or is it re-implemented in C++ library? Why people say "In C++, don't use memcpy for non-POD types? What is...
22
by: Matt | last post by:
When browsing a web page a user has the ability to highlight content on a page (by holding down the left mouse button and dragging the mouse over the desired content). Is there a way to disable...
6
by: solex | last post by:
Hello, I am trying to use serialization to copy objects. The object in question "Institution" inherits from a parent object "Party" both are marked as <Serializable()>. Initially I can copy an...
1
by: chris.atlee | last post by:
I'm writing a program in python that creates tar files of a certain maximum size (to fit onto CD/DVD). One of the problems I'm running into is that when using compression, it's pretty much...
5
by: Frederick Gotham | last post by:
I want to copy an array of objects. If it were C, I'd simply do: memcpy( target_array, source_array, sizeof target_array ); However, this won't suffice for objects in C++.
0
by: RS200Phil | last post by:
Hi all, We have this morning used DTS to copy some objects from one database to another. We removed the tick to "Copy all objects" and selected just the 4 tables that we wanted However, we...
9
by: Julian | last post by:
Hi, I have a vector defined like this: std::vector<Load*LoadList; which is populated with different objects of classes that are derived from 'Load'. I need to make a copy of this list during...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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.