473,320 Members | 2,111 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,320 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 1563
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.