Afficher un message
Vieux 27/05/2008, 21h18   #5
Antoninus Twink
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Optimizing structure memory allocation

On 27 May 2008 at 12:25, rahul wrote:
> How is the memory allocated for structures? I need to optimize the
> memory usage and bit fields are not doing the trick.
>
> PS - I already have asked this in gcc group. Please refrain from
> directing me towards other groups.


You might want to look at gcc's packed attribute, which "specifies that
a variable or structure field should have the smallest possible
alignment - one byte for a variable, and one bit for a field, unless you
specify a larger value with the aligned attribute."

You can either pack specific fields, e.g.

struct foo {
char a;
int b __attribute__((packed));
};

or whole structs at once, e.g.

struct bar {
int a;
char b;
int c;
char d;
int e;
} __attribute__((packed));

  Réponse avec citation
 
Page generated in 0,04720 seconds with 9 queries