Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8973
| From | "Bo Persson" <bop@gmb.dk> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Array inside struct inside container |
| Date | 2011-08-17 12:29 +0200 |
| Message-ID | <9b1jfoFehjU1@mid.individual.net> (permalink) |
| References | <Xns9F43865A8800Dnonenonenone@69.16.186.52> <j2egda$5cc$1@dont-email.me> <Xns9F438F9EC556Bnonenonenone@69.16.186.52> |
none wrote: > Victor Bazarov wrote: > >> A struct with an array as a data member is assignable. The default >> compiler-provided assignment operator performs memberwise >> assignment that for array members means element-wise assignment. > > > Thanks! I was uninformed. I've been using wrapper classes in my > ignorance, which do perform a memcpy(). This means that I could > get rid of them, but based on your example, I think the memcpy() > might be slightly faster. It's a micro-optimization, I know, but > it looks like the compiler inserts something like a for-loop that > invokes operator= for each element, where memcpy() is probably > optimized down to basically a single REP-MOV instruction on x86. > Or, maybe I'm just emotionally attached to my wrapper classes now > and want to continue using them. The compiler can easily optimize the memberwise copy into a memcpy() whenever that is possible (and deemed "slighly faster"). It is an old myth that memcpy() is always the fastest. Smart compilers can do a lot of things that is sometimes ever better (like taking advantage of known alignment and size). Bo Persson
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Array inside struct inside container none <none@none.none> - 2011-08-16 19:12 +0000
Re: Array inside struct inside container Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-16 15:28 -0400
Re: Array inside struct inside container none <none@none.none> - 2011-08-16 20:07 +0000
Re: Array inside struct inside container Leigh Johnston <leigh@i42.co.uk> - 2011-08-16 21:18 +0100
Re: Array inside struct inside container James Kanze <james.kanze@gmail.com> - 2011-08-22 11:01 -0700
Re: Array inside struct inside container Leigh Johnston <leigh@i42.co.uk> - 2011-08-22 20:44 +0100
Re: Array inside struct inside container Leigh Johnston <leigh@i42.co.uk> - 2011-08-22 20:51 +0100
Re: Array inside struct inside container Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-08-16 23:26 +0200
Re: Array inside struct inside container "Bo Persson" <bop@gmb.dk> - 2011-08-17 12:29 +0200
Re: Array inside struct inside container Juha Nieminen <nospam@thanks.invalid> - 2011-08-17 13:06 +0000
Re: Array inside struct inside container yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-08-22 13:20 +0000
Re: Array inside struct inside container Leigh Johnston <leigh@i42.co.uk> - 2011-08-22 14:42 +0100
Re: Array inside struct inside container yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-08-23 09:20 +0000
csiph-web