digitalmars.D.learn - struct .sizeof
- Funog <funog ifrance.com> Aug 28 2006
- Tom S <h3r3tic remove.mat.uni.torun.pl> Aug 28 2006
- Frank Benoit <keinfarbton nospam.xyz> Aug 28 2006
Hi,
I usually program in java, so i'm not used to memory management.
For exemple, i do not understand why the following struct
struct Foo
{
long a;
byte b;
}
has a .sizeof of 16 ? couldn't it fit in 9 bytes ?
Thanks.
Aug 28 2006
Funog wrote:Hi, I usually program in java, so i'm not used to memory management. For exemple, i do not understand why the following struct struct Foo { long a; byte b; } has a .sizeof of 16 ? couldn't it fit in 9 bytes ? Thanks.
Sure it could: align (1) struct Foo { long a; byte b; } static assert (Foo.sizeof == 9);
Aug 28 2006
has a .sizeof of 16 ? couldn't it fit in 9 bytes ? Thanks.
Sure it could: align (1) struct Foo { long a; byte b; } static assert (Foo.sizeof == 9);
Some more background info: http://en.wikipedia.org/wiki/Data_structure_alignment
Aug 28 2006








Frank Benoit <keinfarbton nospam.xyz>