C 使用指针访问shm结构
我有这样一个c结构:C 使用指针访问shm结构,c,memory,pointers,structure,shared,C,Memory,Pointers,Structure,Shared,我有这样一个c结构: struc str{ int values[10]; }str 在类似fedora的posix中,我将此结构复制到共享内存的一部分(shm_open,ftruncate,mmap和memcpy),并从shm获得了指向该结构的指针。现在,我如何使用这个指针(*ptr)更改值数组中的值 假设我想做str->values[5]=10;如何使用指针来执行此操作 只需使用指针: struct str *p = ptr; p->values[5] = 10;
struc str{
int values[10];
}str
在类似fedora的posix中,我将此结构复制到共享内存的一部分(shm_open
,ftruncate
,mmap
和memcpy
),并从shm获得了指向该结构的指针。现在,我如何使用这个指针(*ptr)更改值数组中的值
假设我想做str->values[5]=10;如何使用指针来执行此操作 只需使用指针:
struct str *p = ptr;
p->values[5] = 10;