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

📄 bit_vector.cc

📁 简单的动态内存管理程序源代码
💻 CC
字号:
// file: test/bit_vector.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 <allocator_bit_vector.h>int main(int argc, char **argv) {  int passed=0, failed=0;  // install the tested bit vector in memory at buff  unsigned char buff[125] = {0};  // create a bit vector of 1000 items starting at the address, buff  allocator_bit_vector::allocator_bit_vector_t bit_vec(1000,buff);  std::cerr << "----------------------------------------" << std::endl;  std::cerr << "Bit vector test. " << std::endl;  int set1_start = bit_vec.find_free_items(5);  bit_vec.mark_items(set1_start,5);  std::cerr << "\tReserved 5 blocks starting at block: " << set1_start << std::endl;  if (set1_start==0)     passed++;  else    failed++;  int set2_start = bit_vec.find_free_items(3);  bit_vec.mark_items(set2_start,3);  std::cerr << "\tReserved 3 blocks starting at block: " << set2_start << std::endl;  if (set2_start==5)     passed++;  else    failed++;  int set3_start = bit_vec.find_free_items(7);  bit_vec.mark_items(set3_start,7);  std::cerr << "\tReserved 7 blocks starting at block: " << set3_start << std::endl;  if (set3_start==8)     passed++;  else    failed++;  bit_vec.clear_items(set2_start,2);  std::cerr << "\tCleared 2 blocks starting at block: " << set2_start << std::endl;  if (set2_start==5)     passed++;  else    failed++;  set2_start = bit_vec.find_free_items(3);  bit_vec.mark_items(set2_start,3);  std::cerr << "\tReserved 3 blocks starting at block: " << set2_start << std::endl;  if (set2_start==15)     passed++;  else    failed++;  set2_start = bit_vec.find_free_items(2);  bit_vec.mark_items(set2_start,2);  std::cerr << "\tReserved 2 blocks starting at block: " << set2_start << std::endl;  if (set2_start==5)     passed++;  else    failed++;  set2_start = bit_vec.find_free_items(1);  bit_vec.mark_items(set2_start,2);  std::cerr << "\tReserved 1 block starting at block: " << set2_start << std::endl;  if (set2_start==18)     passed++;  else    failed++;  std::cerr << "Passed: " << passed << std::endl;  std::cerr << "Failed: " << failed << std::endl;  std::cerr << "----------------------------------------" << std::endl;}

⌨️ 快捷键说明

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