473,396 Members | 2,037 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.

Best Way To Copy Complex Structs

Given the following struct definition:

struct Data
{
int i;
ComplexType c;
};
do either of the following copying methods have a programmatic
advantage? Style?

Data d;
Data e;

d.i = 4;
..
..
..
METHOD 1: e = d;
METHOD 2: memcpy(&e,&d, sizeof(d));

Nov 10 '06 #1
2 1691
mieskola wrote:
Given the following struct definition:

struct Data
{
int i;
ComplexType c;
};
do either of the following copying methods have a programmatic
advantage? Style?

Data d;
Data e;

d.i = 4;
.
.
.
METHOD 1: e = d;
METHOD 2: memcpy(&e,&d, sizeof(d));
The second is only guaranteed to work if ComplexType is a POD. Method 1
works for any assignable type. It's also easier to read.

Nov 10 '06 #2
aj
Thanks Rolf. I much prefer method 1 myself.

AJ
Rolf Magnus wrote:
mieskola wrote:
Given the following struct definition:

struct Data
{
int i;
ComplexType c;
};
do either of the following copying methods have a programmatic
advantage? Style?

Data d;
Data e;

d.i = 4;
.
.
.
METHOD 1: e = d;
METHOD 2: memcpy(&e,&d, sizeof(d));

The second is only guaranteed to work if ComplexType is a POD. Method 1
works for any assignable type. It's also easier to read.
Nov 10 '06 #3

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

Similar topics

136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
5
by: spasmous | last post by:
I'm looking into upgrading from version 2 to version 3 of the FFT code package FFTW (www.fftw.org). The two versions are incompatible - a lot of it has to do with changing from a complex struct...
0
by: Arthur Autenzio | last post by:
I have written a managed C++ wrapper class around an old C++ DLL that I have to use in my application. My problem is I need to marshal a bunch of structures from C# to the C++ class. These...
3
by: Derek Martin | last post by:
Hi list, I have been doing VB.Net for quite a while now and just now getting into the forray of ASP.Net using VS2003. I have created our development website and now we are ready to start putting...
24
by: rdc02271 | last post by:
Hello! Is this too crazy or not? Copy constructor: why can't I copy objects as if they were structs? I have a set of simple objects (no string properties, just integers, doubles) and I have to...
20
by: Joel Hedlund | last post by:
Hi all! I use python for writing terminal applications and I have been bothered by how hard it seems to be to determine the terminal size. What is the best way of doing this? At the end I've...
55
by: Steve | last post by:
I have to develop several large and complex C++ hardware test programs that should work under DOS, most likely with 32-bit DOS extender. Development workstation OS would be Microsoft XP. Quite some...
6
by: Dhirendra Singh | last post by:
Hi, In the below example, does copy constructor has any role in the initialization ? class complex { private: double re, im; public: complex( double r = 0, double i = 0) :re(r), im(i) {}...
2
by: =?Utf-8?B?RWl0YW4=?= | last post by:
Hello, Suppose I have created 2 objects of MyClass: MyClass myClass1 = new MyClass(); MyClass myClass2 = new MyClass(); I also defined variables inside MyClass1: myClass1.myVar1 = 1 ;
7
by: Peter Olcott | last post by:
Why can a union have a member with a copy constructor?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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,...
0
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...

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.