root/SharedMemoryCommon.hpp

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /* -*- coding: utf-8; mode: c++; -*-
   2  * Concordance to A. S. Pushkin's Works - Shared Memory operation header
   3  * $Id: SharedMemoryCommon.hpp 51 2014-06-10 06:41:57Z isao $
   4  * Copyright (C) 2012, isao yasuda
   5  */
   6 
   7 #ifndef SHARED_MEMORY_COMMON
   8 #define SHARED_MEMORY_COMMON
   9 
  10 #include <boost/interprocess/managed_shared_memory.hpp>
  11 #include <boost/interprocess/allocators/allocator.hpp>
  12 #include <boost/interprocess/containers/map.hpp>
  13 #include <boost/interprocess/containers/string.hpp>
  14 #include <boost/interprocess/containers/vector.hpp>
  15 #include <boost/interprocess/offset_ptr.hpp>
  16 #include <boost/regex.hpp>
  17 #include <boost/regex/icu.hpp>
  18 #include <iostream>
  19 #include <fstream>
  20 #include <sstream>
  21 #include <cstdlib>
  22 #include <csignal>
  23 
  24 using namespace boost::interprocess;
  25 
  26 // Typedefs of allocators and containers
  27 typedef managed_shared_memory::segment_manager   segment_manager_t;
  28 typedef allocator<void, segment_manager_t>       void_allocator;
  29 typedef allocator<char, segment_manager_t>       char_allocator;
  30 typedef basic_string<char, std::char_traits<char>, char_allocator> char_string;
  31 typedef allocator<char_string, segment_manager_t> string_allocator;
  32 typedef std::pair<const char_string, char_string> cormap_type;
  33 typedef allocator<cormap_type, segment_manager_t> cormap_type_allocator;
  34 typedef map<char_string, char_string, std::less<char_string>,
  35         cormap_type_allocator> shmmap_type;
  36 typedef shmmap_type::iterator Shmit;
  37 
  38 // shared memory constants
  39 static const char* SHMTREE = "ShmWordTree";    // 共有メモリ名 Word Tree
  40 static const char* SHMCRPS = "ShmCorpus";      // 共有メモリ名 Corpus
  41 static const char* SHMWORK = "ShmWork";        // 共有メモリ名 Work
  42 static const int   SHMTRSZ = 1024 * 1024 * 60; // 共有メモリサイズ Word Tree
  43 static const int   SHMCRSZ = 1024 * 1024 * 30; // 共有メモリサイズ Corpus
  44 static const int   SHMWKSZ = 1024;             // 共有メモリサイズ Work
  45 static const int   MNGSIZE = 1024;             // 管理領域(使用不可エリア)サイズ
  46 
  47 // 共有メモリを開始前と終了後に削除する remover
  48 struct shm_wtree_remove {
  49     shm_wtree_remove()
  50     {
  51         shared_memory_object::remove(SHMTREE);
  52     }
  53     ~shm_wtree_remove()
  54     {
  55         std::cout << "Word Tree Shared Memory Deconstruction.\n";
  56         shared_memory_object::remove(SHMTREE);
  57     }
  58 };
  59 
  60 struct shm_corpus_remove {
  61     shm_corpus_remove()
  62     {
  63         shared_memory_object::remove(SHMCRPS);
  64     }
  65     ~shm_corpus_remove()
  66     {
  67         std::cout << "Corpus Shared Memory Deconstruction.\n";
  68         shared_memory_object::remove(SHMCRPS);
  69     }
  70 };
  71 
  72 struct shm_work_remove {
  73     shm_work_remove()
  74     {
  75         shared_memory_object::remove(SHMWORK);
  76     }
  77     ~shm_work_remove()
  78     {
  79         std::cerr << "Concordance Shared Memory Deconstruction.\n";
  80         shared_memory_object::remove(SHMWORK);
  81     }
  82 };
  83 
  84 #endif

/* [previous][next][first][last][top][bottom][index][help] */