C#] Struct 내부 byte[] 사이즈..
struct A
{
public UInt32 test1;
public byte test2;
public byte test3;
public test4;
public byte[] Reserved;
public A(UInt32 test1, byte test2, byte test3, byte test4)
{
this.test1 = test1;
this.test2 = test2;
this.test3 = test3;
this.test4 = test4;
this.Reserved = new byte[9];
}
라고 구조체를 선언한 뒤,
A a = new A(1,2,3,4);
int size;
size = Marshal.SizeOf(a);
이렇게 사이즈를 재보니 size = 12가 나오네요..
packing을 위해 [StructLayout(LayoutKind.Sequential, Pack = 1)]
붙히면 11바이트로 오히려 더 줄어드네요;;
array를 uint32 2개 byte 1개로 수정하면 정상적인 사이즈가 나옵니다.
array를 4byte로 인식하기때문인거 같은데요
원인은 대강 알거 같긴한데 array로 잡으면서 사이즈를 정확하게 표시하려면 어떤방법을 써야하나요?
댓글 달기