[英]problem with matrix in shared memory System V C
I have a problem using a matrix in a shared memory in C.我在 C 的共享 memory 中使用矩阵时遇到问题。
I have synthesize the code here:我在这里合成了代码:
#define MATRIX 1518
int (*matrix)[5], shmMatrix;
shmMatrix = shmget(MATRIX, sizeof(int[5][9]), IPC_CREAT | IPC_EXCL | 0770);
matrix = shmat(shmMatrix, NULL, 0);
for (int i = 1; i <= 8; i++) matrix[0][i] = -5;
but if i print the matrix in shm, this appears:但是如果我在 shm 中打印矩阵,则会出现:
| 0 -5 -5 -5 -5 -5 -5 -5 -5 |
| -5 -5 -5 -5 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
| 0 0 0 0 0 0 0 0 0 |
for the creation of the matrix in shm, I used this suggestion为了在 shm 中创建矩阵,我使用了这个建议
I found a solution.我找到了解决方案。
I have to change the number of row (5) with the number of columns (9) when I create the array of pointer.当我创建指针数组时,我必须用列数 (9) 更改行数 (5)。
(*matrix)[9];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.