请你帮助我好吗? 我不能增加我的谢尔德记忆的大小。 代码在Linux上用C语言编写。
我需要65536字节,但似乎只允许49152 …如果我增加它,shmget失败…(在我的代码中: shmid < 0
)我试图找出我的最大共享内存大小并增加它:
sysctl -w kernel.shmmax=2147483648
但这没有帮助,初始化再次失败。
这是我的代码:
#define SHM_KEY 9877 #define SHM_SIZE 65536 int SHM_init (int shmid, char** shm, key_t key, long int size) { /* Create a new (System V) shared memory segment of the specified size */ shmid = shmget(key, SHM_SIZE, IPC_CREAT|0777); /* Check if SHM creation was successful */ if (shmid < 0) { /* DBG: Debug message to show which point of the program has been passed */ DBG_PRINT("Cn"); /* Check if creation failed because of already existing SHM */ if (EEXIST == errno) { /* DBG: Debug message to show which point of the program has been passed */ DBG_PRINT("CCn"); /* Delete already existing SHM with shmctl */ shmctl(shmid, IPC_RMID, NULL); } else { /* DBG: Debug message to show which point of the program has been passed */ DBG_PRINT("CCCn"); } /* Creation and initialization of SHM failed */ return -1; } /* Attach the SHM data pointer to the previously created SHM segment */ *shm = shmat(shmid, NULL, 0); if(*shm == (char *) -1) { /* Attaching failed */ return -1; } DBG_PRINT("Shared Memory Initialization successfuln"); /* Creation and initialization of shared memory was successful */ return 0; }
非常感谢你…
这个主题可能有帮助。 如果使用sysctl -w kernel.shmmax=2147483648
增加shmmax, ipcs -l
返回什么?
以上就是c/c++开发分享无法增加共享内存的大小相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/523169.html