| 17 | } |
| 18 | |
| 19 | void DiskVectorBase::init(size_t byte_size) |
| 20 | { |
| 21 | if (file.is_open()) |
| 22 | throw runtime_error("resizing of disk memory not implemented"); |
| 23 | else |
| 24 | { |
| 25 | auto dir_path = OnlineOptions::singleton.disk_memory; |
| 26 | boost::filesystem::path dir(dir_path); |
| 27 | if (not boost::filesystem::is_directory(dir)) |
| 28 | throw std::runtime_error(dir_path + " is not a directory"); |
| 29 | |
| 30 | path = boost::filesystem::unique_path( |
| 31 | (dir / std::string("%%%%-%%%%-%%%%-%%%%")).native()); |
| 32 | |
| 33 | std::ofstream f(path.native()); |
| 34 | f.close(); |
| 35 | } |
| 36 | |
| 37 | if (truncate(path.native().c_str(), byte_size)) |
| 38 | throw std::runtime_error( |
| 39 | "cannot allocate " + std::to_string(byte_size) + " bytes in " |
| 40 | + path.native() + ": " + strerror(errno)); |
| 41 | |
| 42 | file.open(path, boost::iostreams::mapped_file::readwrite, byte_size); |
| 43 | assert(file.size() == byte_size); |
| 44 | |
| 45 | boost::filesystem::remove(path); |
| 46 | |
| 47 | signal(SIGBUS, sigbus_handler); |
| 48 | } |
no test coverage detected