gpt4 book ai didi

无法增加共享内存的大小

转载 作者:行者123 更新时间:2023-11-30 15:13:39 27 4
gpt4 key购买 nike

你能帮我一下吗?我无法增加碎片内存的大小。该代码是在 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("C\n");

/* 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("CC\n");
/* 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("CCC\n");
}

/* 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 successful\n");
/* Creation and initialization of shared memory was successful */
return 0;
}

提前非常感谢...

最佳答案

This topic可能有帮助。如果使用 sysctl -w kernel.shmmax=2147483648 增加 shmmax,ipcs -l 会返回什么?

关于无法增加共享内存的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34471969/

27 4 0
文章推荐: javascript - Angular 2 将 JSON 对象传递到新窗口
文章推荐: c# - 当前上下文中不存在名称 'ARSubsystemManager'
文章推荐: javascript - 将平面数组解析为嵌套结构(树)
文章推荐: c# - 如何序列化 List 同时转义特殊字符?