using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
public class MemoryAlignment : MonoBehaviour
{
[StructLayout(LayoutKind.Auto)]
struct StructA
{
public int num;
public int num1;
public long num2;
}
[StructLayout(LayoutKind.Explicit)]
struct StructB
{
[FieldOffset(0)]
public int num;
[FieldOffset(0)]
public long num2;
[FieldOffset(0)]
public int num1;
}
void Start()
{
StructA stru = new StructA();
Debug.LogError("num的长度:" + Marshal.SizeOf(stru.num));
//Debug.LogError("ch的长度:" + Marshal.SizeOf(stru.ch));
//Debug.LogError("StructA的长度:" + Marshal.SizeOf(stru));
unsafe
{
Debug.LogError("StructA的长度:" + sizeof(StructA));
Debug.LogError("StructB的长度:" + sizeof(StructB));
}
}
}