当前位置:网站首页>Shared memory - shmget filling holes
Shared memory - shmget filling holes
2022-07-29 14:23:00 【A corner of peace, occupying the mountain as the king】
shmget设置的size值,不能大于最大值SHMMAXand is less than the minimum valueSHMMIN
且若是keyThe segment corresponding to the value already exists,Then use it latershmget的sizeThe value must be less than or equal to the original value function
Then I asked the programmer,He set20kB,个人是100kB,And his settings are to start at boot,So it was me who made the mistake every time,悲催!
/******************************************************************************
*函数名称:yg_init_mem_share
*功能描述: 初始化共享内存(Used to store map calibration data)
*全局影响:无
*输入:
*输出:无
*返回值:0:成功 -1:发送失败
* 做者 日期 内容
* Jimmy 2018-10-16 建立
*
******************************************************************************/
void yg_init_mem_share(int size)
{
key_t key;
//int size = 1024*1024; //1M内存大小
//1. 建立共享内存
if(-1 == (key = ftok("/", 4)))
{
bv_loge("ftok failed [%d:%s]!", errno, strerror(errno));
bv_error_handle("ftok failed [%d:%s]!", errno, strerror(errno));
return ;
}
bv_logd("key=%#x!", key);
SHM_ID = shmget(key, (size_t)size, IPC_CREAT|0644);
if(-1 == SHM_ID)
{
bv_loge("Init the shared memory[%dKB] failed [%d:%s]!",size/1024, errno, strerror(errno));
bv_error_handle("Init the shared memory[%dKB] failed [%d:%s]!",size/1024, errno, strerror(errno));
}
else
{
bv_logd("Init the shared memory[%dKB] OK!", size/1000);
bv_file_log(g_tcp_fp, "Init the shared memory[%dKB] OK!", size/1000);
}
return ;
}
The above is copied from others,意思就是说,你先创建了一个KEY对应的文件,比如说是K1,现在程序运行时K1对应的内存SIZE是1000字节,Later you want to expand this memory,Modify the allocated memory directly,最大还是1000字节,只有删掉K1对应的文件,Recreate and allocate larger memory,才能满足.
边栏推荐
猜你喜欢
84.(cesium之家)cesium模型在地形上运动
【JS面试题】面试官问我:遍历一个数组用 for 和 forEach 哪个更快?
leetcode linked list topic
【FreeSwitch开发实践】自定义模块创建与使用
Still developing SMS verification code login?Try it (one-click login with your phone number)
EA&UML日拱一卒-活动图::Object actions(续)
潘多拉 IOT 开发板学习(RT-Thread)—— 实验19 MQTT 协议通信实验(学习笔记)
AI全流程开发难题破解之钥
FPGA刷题——跨时钟域传输(FIFO+打拍+握手)
小程序开发模板设计怎么做?
随机推荐
BOM系列之Location对象
深开鸿:万物智联的大江上,升起一轮开源鸿蒙月
暴力递归到动态规划 02 (绝顶聪明的人的纸牌游戏)
已解决SyntaxError: invalid character in identifier
[10:00 Open Class]: Application Exploration of Kuaishou GPU/FPGA/ASIC Heterogeneous Platform
2022年七夕情人节有什么值得推荐的礼物选择?实用且高级礼物推荐
Vscode builds ESP32-C3 development environment
开关电源-半桥LLC控制
这么多年了,还搞不懂正则语法?
线程池面试汇总
第二轮Okaleido Tiger热卖的背后,是背后生态机构战略支持
为什么字符串使用final关键字
在金融服务行业数字化转型中,低代码值得被关注
共享内存 - shmget填坑记
How much do you know about futures contracts
力扣 206.反转链表--递归解决
【JS面试题】面试官问我:遍历一个数组用 for 和 forEach 哪个更快?
2022年了!还在用定时器实现动画?赶紧试试requestAnimationFrame吧!
84.(cesium之家)cesium模型在地形上运动
简单了解单例模式