Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Question about memcopying damned structs

Author: Paul Clarke

Date: 04:07:07 07/26/04

Go up one level in this thread


On July 24, 2004 at 12:56:11, Matthias Gemuh wrote:
>
>a) memcpy(&ChsStrct->PlyData[ChsStrct->nPly+1],
> &ChsStrct->PlyData[ChsStrct->nPly], sizeof(PLYDATA));
>
>b) ChsStrct->PlyData[ChsStrct->nPly+1] = ChsStrct->PlyData[ChsStrct->nPly];
>
>
>Will either of these copy the array element of type struct PLYDATA ?.
>Any special thing to mention concerning speed, padding, aligninment ?

If you're writing C, either should work. I'd expect the assignment to be no
slower, and possibly faster as it gives the compiler more information to work
with. I also find (b) to be clearer, so I can't see any reason to use (a).

If you're writing C++ then there's anothe drawback to (a): if PLYDATA needs to
override the assignment operator then using (a) will almost certainly cause
bugs.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.