#include #include //#include #include #include "boost/filesystem.hpp" #include #include //using namespace boost::interprocess; typedef boost::interprocess::allocator CCharAllocator; typedef boost::interprocess::basic_string, CCharAllocator> CString; typedef boost::interprocess::allocator, boost::interprocess::managed_mapped_file::segment_manager> CMapAllocator; typedef boost::interprocess::map, CMapAllocator> CMap; int main(int argc, char **argv) { try { boost::interprocess::managed_mapped_file sFile( boost::interprocess::open_or_create, "MyMappedFile.dat", 1024*1024*1024); //CMapAllocator sAllocator(sFile); CMap *const pMap= sFile.find_or_construct("map")(CMap::key_compare(), CMap::stored_allocator_type(sFile.get_segment_manager())); std::string sLine; while (std::getline(std::cin, sLine)) { //CString sLine(CString::stored_allocator_type(sFile.get_segment_manager())); if (boost::filesystem::exists(sLine) && boost::filesystem::is_regular(sLine)) if (argc != 1) { CMap::const_iterator p = pMap->find(CString(sLine.c_str(), sLine.size(), CCharAllocator(sFile.get_segment_manager()))); if (p != pMap->end()) std::cout << p->second << "\n"; else std::cout << "not found\n"; } else pMap->insert(std::make_pair(CString(sLine.c_str(), sLine.size(), CCharAllocator(sFile.get_segment_manager())), boost::filesystem::file_size(sLine))); } } catch (const std::exception &_r) { std::cerr << _r.what() << "\n"; return 1; } return 0; }