www.pudn.com > allocator.rar > mult_proc.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   
#include 
#include 
#include   // 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 my_vector_alloc_t;
  
  typedef std::vector my_vector_t;

  pooled_allocator::Multi_Process_Pool_alloc 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;
}