📄 shm.cpp
字号:
/*************************************************************************** shm.cpp - description ------------------- begin : Fri Jul 20 2001 copyright : (C) 2001 by Mark email : alben@yeah.net ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include <errno.h>#include "shm.h"CShm::CShm(key_t tKey, int iSize, int iMode) : m_tShmKey(tKey), m_iShmSize(iSize){ GetShm(iMode); AttachShm();}CShm::~CShm(){ DetachShm();}void CShm::GetShm(int iMode){ if ((m_iShmId = shmget(m_tShmKey, m_iShmSize, IPC_CREAT | IPC_EXCL | iMode)) < 0) //try to create { if (errno != EEXIST) throw CShmException(strerror(errno), __FILE__, __LINE__); if ((m_iShmId = shmget(m_tShmKey, m_iShmSize, iMode)) < 0) throw CShmException(strerror(errno), __FILE__, __LINE__); m_bCreate = false; return; } m_bCreate = true;}void CShm::AttachShm(){ if ((m_pchShm = (char*)shmat(m_iShmId, NULL, 0)) < 0) throw CShmException(strerror(errno), __FILE__, __LINE__);}void CShm::DetachShm(){ if (shmdt(m_pchShm) < 0) throw CShmException(strerror(errno), __FILE__, __LINE__);}void CShm::RemoveShm(){ if (shmctl(m_iShmId, IPC_RMID, NULL) < 0) throw CShmException(strerror(errno), __FILE__, __LINE__);}void CShm::InitShm(){ memset(m_pchShm, 0, m_iShmSize);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -