| Thread overview | |||||
|---|---|---|---|---|---|
| 
 | 
| August 28, 2006struct .sizeof | ||||
|---|---|---|---|---|
| 
 | ||||
| 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.
 | ||||
| August 28, 2006Re: struct .sizeof | ||||
|---|---|---|---|---|
| 
 | ||||
| Posted in reply to Funog | 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);
 | |||
| August 28, 2006Re: struct .sizeof | ||||
|---|---|---|---|---|
| 
 | ||||
| Posted in reply to Tom S | >> 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 | |||
Copyright © 1999-2021 by the D Language Foundation
  Permalink
Permalink Reply
Reply