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

📄 main.cc

📁 简单的动态内存管理程序源代码
💻 CC
字号:
// file: main.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.#include <iostream>  #include <pooled_allocator.h>#include <vector>char key_val[] = "/allocate_key";  // needs a leading slash, see manpage.char key_container[] = "container_lookup_key";char key_addr[] = "0x400d0000";int main(int argc, char** argv) {  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> temp_alloc;  my_vector_t* vec_ptr = temp_alloc.attach();  const int& segment_num = temp_alloc.get_proj_id();  const int& segment_page_num = temp_alloc.get_segment_page_num();  temp_alloc.lock(segment_num,segment_page_num);  std::cout << "Insert ints" << std::endl;  for (int i = 0; i < 5000; i++) {    vec_ptr->push_back(i);    std::cout << "Pushed a " << i << "\t Read a " << (*vec_ptr)[i] << std::endl;  };  temp_alloc.unlock(segment_num,segment_page_num);  std::cout << "Read 1st time" << std::endl;  for (my_vector_t::iterator it = vec_ptr->begin();       it != vec_ptr->end(); it++)    std::cout << "Vector val: " << *it << std::endl;  std::cout << "Read 2nd time" << std::endl;  for (my_vector_t::iterator it = vec_ptr->begin();       it != vec_ptr->end(); it++)    std::cout << "Vector val: " << *it << std::endl;  return 0;}

⌨️ 快捷键说明

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