Re: Optimizing structure layout

Valentin Bonnard <bonnardv@pratique.fr>
31 Mar 1997 22:20:25 -0500

          From comp.compilers

Related articles
[2 earlier articles]
Re: Optimizing structure layout fjh@mundook.cs.mu.OZ.AU (1997-03-22)
Re: Optimizing structure layout cdg@nullstone.com (Christopher Glaeser) (1997-03-22)
Re: Optimizing structure layout meissner@cygnus.com (Michael Meissner) (1997-03-27)
Re: Optimizing structure layout dlmoore@ix.netcom.com (David L Moore) (1997-03-27)
Re: Optimizing structure layout tl@funcom.com (1997-03-31)
Re: Optimizing structure layout pieper@zko.dec.com (John Pieper) (1997-03-31)
Re: Optimizing structure layout bonnardv@pratique.fr (Valentin Bonnard) (1997-03-31)
| List of all articles for this month |
From: Valentin Bonnard <bonnardv@pratique.fr>
Newsgroups: comp.compilers
Date: 31 Mar 1997 22:20:25 -0500
Organization: Internet Way
References: 97-03-130 97-03-157
Keywords: storage, optimize, C++

erik.schnetter@student.uni-tuebingen.de writes:
  > While it is quite common that compilers optimize the code they
  > produce, I haven't heard of a commonly used system that really
  > optimizes the layout of the data structures that are generated. Are
  > there such systems?


Michael Meissner wrote:
> For many languages, it is impossible. C for one requires that
> structure members be laid out in the order the programmer wrote
> them. I believe C++ allows classes to be optimized, but again, not
> structures.


No, class and struct aren't different at all.


The only case where th order is unspecified is like this one:


struct T { // or class
          int i;
public:
          int j;
};


The position of i compared to j is unspecified; this
isn't sufficient to do usefull optimisations.


IMO this is bad; it prevent optimisations such as:


struct T {
          char c1;
          int i;
          char c2;
};


sizeof (T) == 12


vs


struct T2 {
          int i;
          char c1;
          char c2;
};


sizeof (T2) == 8


Layout of T1
pos size type name
0 1 char c1
1 3 padding
4 4 int i
8 1 char c2
9 3 padding
12


Layout of T2
pos size type name
0 4 int i
4 1 char c1
5 1 char c2
6 3 padding
8
--


Valentin Bonnard
mailto:bonnardv@pratique.fr
http://www.pratique.fr/~bonnardv (Informations sur le C++ en Francais)
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.