Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Phil Carmody <thefatphil_demunged@yahoo.co.uk> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | Re: Structure Packing. |
| Date | 2012-06-18 12:37 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <87zk81arlo.fsf@bazspaz.fatphil.org> (permalink) |
| References | (5 earlier) <a3p9irFkgbU1@mid.dfncis.de> <4FD79328.A040F7B8@bytecraft.com> <jr88ej$qan$1@dont-email.me> <4FD7B831.8B6BBEB9@bytecraft.com> <a3rkb6Fb4tU1@mid.dfncis.de> |
Hans-Bernhard Bröker <HBBroeker@t-online.de> writes:
> On 12.06.2012 23:44, Walter Banks wrote:
> > Eric Sosman wrote:
>
> >> Perhaps structs are not the right tool for the job? Instead of
> >>
> >> struct {
> >> unsigned char flag;
> >> double value;
> >> } data[1000];
> >>
> >> ... you might do better to write
> >>
> >> unsigned char data_flag[1000];
> >> double data_value[1000];
>
> Or the slightly less obscure
>
> struct {
> unsigned char flag[1000];
> double value[1000];
> } data;
>
> I guess one big reason that array-of-structs is favoured over this
> struct-of-arrays approach quite a lot these days is that all those
> caches favour locality over dense packing.
Hopping from index to index or running through linked lists to only
access a limited subset of the fields would have improved locality
as well as dense packing. A locality of reference argument which
assumes that each time you want to access any part of a struct you
want to access it all is a very flawed one. However, that's highly
domain specific, and neither the language nor the compiler can
assist you post-facto, you simply have to select the data structure
you think (or measure) is best. OK, it helps by letting you
abstract the data layout via zero-cost accessor functions (or macros
if you're stuck in the 80s), but some might find that too clumsy,
YMMV.
Phil
--
> I'd argue that there is much evidence for the existence of a God.
Pics or it didn't happen.
-- Tom (/. uid 822)
Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Structure Packing. John Kearney <dethrophes@googlemail.com> - 2012-06-06 17:27 -0700
Re: Structure Packing. James Kuyper <jameskuyper@verizon.net> - 2012-06-06 21:19 -0400
Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-11 22:39 -0400
Re: Structure Packing. Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-12 09:21 -0400
Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-12 11:51 -0400
Re: Structure Packing. Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-06-12 18:37 +0200
Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-12 15:06 -0400
Re: Structure Packing. Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-12 16:22 -0400
Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-12 17:44 -0400
Re: Structure Packing. Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-06-13 15:53 +0200
Re: Structure Packing. Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-06-18 12:37 +0300
Re: Structure Packing. Martin Shobe <martin.shobe@yahoo.com> - 2012-06-12 16:22 +0000
Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-12 15:24 -0400
Re: Structure Packing. Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-12 16:33 -0400
Re: Structure Packing. Walter Banks <walter@bytecraft.com> - 2012-06-12 17:17 -0400
Re: Structure Packing. Keith Thompson <kst-u@mib.org> - 2012-06-06 18:35 -0700
Re: Structure Packing. John Kearney <dethrophes@googlemail.com> - 2012-06-06 21:58 -0700
Re: Structure Packing. Keith Thompson <kst-u@mib.org> - 2012-06-06 23:54 -0700
Re: Structure Packing. John Kearney <dethrophes@googlemail.com> - 2012-06-07 07:47 -0700
Re: Structure Packing. James Kuyper <jameskuyper@verizon.net> - 2012-06-07 12:39 -0400
Re: Structure Packing. jacob navia <jacob@spamsink.net> - 2012-06-07 11:14 +0200
Re: Structure Packing. Keith Thompson <kst-u@mib.org> - 2012-06-07 09:46 -0700
Re: Structure Packing. John Kearney <dethrophes@googlemail.com> - 2012-06-07 11:57 -0700
csiph-web