Length of a struct

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello NG,

I have two structs.
The only differnce is the order of the members:


public struct DataStruct
{
public UInt16 Sekunde;
public UInt32 BehälterId;
public UInt32 WannenNr;
public UInt16 Station;
};

public struct DataStruct
{
public UInt32 BehälterId;
public UInt32 WannenNr;
public UInt16 Station;
public UInt16 Sekunde;
};


If I use SizeOf for the struct it is 16 forthe first and 12 for the second
struct.
The right value should by 12.

If I change the order, why do I get another length ?

regards
Stephan
 
Stephan said:
Hello NG,

I have two structs.
The only differnce is the order of the members:

public struct DataStruct
{
public UInt16 Sekunde;
public UInt32 BehälterId;
public UInt32 WannenNr;
public UInt16 Station;
};

public struct DataStruct
{
public UInt32 BehälterId;
public UInt32 WannenNr;
public UInt16 Station;
public UInt16 Sekunde;
};

If I use SizeOf for the struct it is 16 forthe first and 12 for the second
struct. The right value should by 12.

If I change the order, why do I get another length ?

Suspiciously looks like memory alignment to me. Each field in the struct
is multiple of four bytes.
 
Back
Top