⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shm_unlink.cc

📁 简单的动态内存管理程序源代码
💻 CC
字号:
// file: shm_unlink.cc// author: Marc Bumble// April 29, 2003// Page memory source for shared memory // Copyright (C) 2003 by Marc D. Bumble//  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.//  This program is distributed in the hope that it will be useful,//  but WITHOUT ANY WARRANTY; without even the implied warranty of//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//  GNU General Public License for more details.//  You should have received a copy of the GNU General Public License//  along with this program; if not, write to the Free Software//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.extern "C" {  // #include <sys/types.h>#include <unistd.h>  /* POSIX et al */#include <sys/mman.h>#include <fcntl.h>     // for O_RDWR | O_CREAT | O_TRUNC}#include <iostream>  #include <fstream>  // for std::ofstream to()#include <sstream>		// string stream for stringstream#include <pooled_allocator.h>char  key_val_1[] = "/allocate_key";  // needs a leading slash, see manpage.char  key_val_2[] = "/allocate_key2";  // used in Pool testint main(int argc, char** argv) {  for (int proj_id=0; proj_id <=5; proj_id++) {    // create the shared segment key    std::stringstream alloc_key_ss;    alloc_key_ss << key_val_1 << "_" << proj_id;    // unlink shared memory    int result = shm_unlink(alloc_key_ss.str().data());    //     if (errno!=ENOENT) {    if (!result) {      std::clog << "shm_unlink released " << alloc_key_ss.str() << std::endl;      std::clog << "Status: " << __FILE__ << ':' << __LINE__ ;      std::clog << ": shared memory shm_unlink: " << strerror(errno) <<	":  " << alloc_key_ss.str().data() << std::endl;    }  }  // for (int i=0; i <=127; i++)  for (int proj_id=0; proj_id <=5; proj_id++) {    // create the shared segment key    std::stringstream alloc_key_ss;    alloc_key_ss << key_val_2 << "_" << proj_id;    // unlink shared memory    int result = shm_unlink(alloc_key_ss.str().data());    //     if (errno!=ENOENT) {    if (!result) {      std::clog << "shm_unlink released " << alloc_key_ss.str() << std::endl;      std::clog << "Status: " << __FILE__ << ':' << __LINE__ ;      std::clog << ": shared memory shm_unlink: " << strerror(errno) <<	":  " << alloc_key_ss.str().data() << std::endl;    }  }  // for (int i=0; i <=127; i++)      return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -