本文介绍了Accesing使用指针SHM结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个C的结构是这样的:
I have a c structure like this :
struc str{
int values[10];
}str
在一个POSIX所以如Fedora我复制这个结构到共享内存中的一部分(的shm_open
, ftruncate
, MMAP
和的memcpy
),我得到一个指针从SHM构造。现在我该怎样利用这个指针(* PTR)更改数值数组中的值。
In a posix so like fedora i copied this structure to a part of shared memory (shm_open
, ftruncate
, mmap
and memcpy
) and I got a pointer to structure from shm. Now how do I change a value in the values array by using this pointer (*ptr).
想象一下,我想要做的STR->值[5] = 10;怎么我这样做,使用指针。
Imagine i want to do str->values[5] = 10; how to I do that using the pointer.
推荐答案
只需使用指针:
struct str *p = ptr;
p->values[5] = 10;
这篇关于Accesing使用指针SHM结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!