找回密码
 立即注册
首页 业界区 安全 C#与C++动态链接库数据传递

C#与C++动态链接库数据传递

腥狩频 2025-6-9 07:52:15
1 内存对齐规则


  • 结构体的数据成员,第一个成员的偏移量为0,后面每个成员变量的地址必须从其大小的整数倍开始。
  • 子结构体中的第一个成员偏移量应当是子结构体中最大成员的整数倍。
  • 结构体的总大小必须是其内部最大成员的整数倍
示例
[code]#include using namespace std;struct Frame {    unsigned char id; // 0-1    int width; // 4-8    long long height; // 8-16    unsigned char* data; // 16-24 (x64) 16-20 (x86) 指针x86下是4字节    int size; // 24-28};struct Info {    char name[10];//0-10    double value;        //16-24    Frame fr; // 24-56};int main() {        Frame frame;        Info info;    cout
您需要登录后才可以回帖 登录 | 立即注册