hi all,
if i want to use pointers inside shared memory, how do i have to get and attach it. For example...
struct shm {
int *numbers;
int i1;
int i2;
int i3;
} *pshm;
Say i have N numbers to put into the array, then...
IDshm = shmget(KEY, (4*N)+4+4+4, IPC_CREAT | 0666)
then attach...
pshm = (struct shm*)shmat(IDshm, 0, 0)
Then i have a pointer to the shared memory segment.
To get the pointer to the array inside the structure...
pshm->numbers = (int *)pshm[4]; ( 4 ----> size of the pointer )
Is this ok? My application throws a segmentation fault and i think it could be the problem. The program is not so simple as above so this could not be the wrong thing.
I think that my explanation is not quite well ( as my english ), but i hope someone will help me...
thanx.
gracias.
gràcies.
a10.
if i want to use pointers inside shared memory, how do i have to get and attach it. For example...
struct shm {
int *numbers;
int i1;
int i2;
int i3;
} *pshm;
Say i have N numbers to put into the array, then...
IDshm = shmget(KEY, (4*N)+4+4+4, IPC_CREAT | 0666)
then attach...
pshm = (struct shm*)shmat(IDshm, 0, 0)
Then i have a pointer to the shared memory segment.
To get the pointer to the array inside the structure...
pshm->numbers = (int *)pshm[4]; ( 4 ----> size of the pointer )
Is this ok? My application throws a segmentation fault and i think it could be the problem. The program is not so simple as above so this could not be the wrong thing.
I think that my explanation is not quite well ( as my english ), but i hope someone will help me...
thanx.
gracias.
gràcies.
a10.