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

📄 mult_proc.cc

📁 简单的动态内存管理程序源代码
💻 CC
字号:
// file: test/multi_process_pool_alloc.cc// author: Marc Bumble// Mon Aug 11, 2003// Memory allocator code for shared memory access// 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.#include <iostream>  #include <vector>#include <pooled_allocator.h>#include <fstream>  // for std::ofstream to()char  key_val[] = "/allocate_key";char key_container[] = "container_lookup_key";char key_addr[] = "0x400d0000";int main(int argc, char **argv) {  int passed=0, failed=0;  typedef pooled_allocator::Pool_alloc<int,    key_val,    key_addr> my_vector_alloc_t;    typedef std::vector<int,my_vector_alloc_t> my_vector_t;  pooled_allocator::Multi_Process_Pool_alloc<my_vector_t,    int,    key_val,    key_container,    key_addr> multi_proc_alloc;  std::cerr << "----------------------------------------" << std::endl;  std::cerr << "Multi_Process_Pool_Alloc class tests. " << std::endl;  my_vector_t* vec_ptr = multi_proc_alloc.attach();  const int& segment_num = multi_proc_alloc.get_proj_id();  const int& segment_page_num = multi_proc_alloc.get_segment_page_num();  multi_proc_alloc.lock(segment_num,segment_page_num);  std::cout << "Insert ints" << std::endl;  //  causes a fault  for (int i = 0; i < 5012; i++) {    vec_ptr->push_back(i);    // std::cout << "Pushed a " << i << "\t Read a " << (*vec_ptr)[i] << std::endl;  };  // Check values  for (int i = 0; i < 5012; i++) {    if (i == (*vec_ptr)[i])       passed++;    else       failed++;  }  multi_proc_alloc.unlock(segment_num,segment_page_num);    std::cerr << "Passed: " << passed << std::endl;  std::cerr << "Failed: " << failed << std::endl;  std::cerr << "----------------------------------------" << std::endl;  return 0;}

⌨️ 快捷键说明

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