4

大きな圧縮ファイルを処理する予定であり、読み取りを高速化するためにファイルをメモリマップしたいと思います。通常のファイル入力で既存の例を採用しましたが、コンパイルも動作もできません:-) C ++Boost1.49を使用しています

どんな提案も歓迎します!

#include<iostream>
#include<boost/iostreams/filtering_streambuf.hpp>
#include<boost/iostreams/copy.hpp>
#include<boost/iostreams/filter/zlib.hpp>
#include<boost/iostreams/device/file.hpp>
#include<boost/iostreams/device/mapped_file.hpp>

void test_decoder_mmf()
{
   using namespace std;
   using namespace boost::iostreams;
   //ifstream file("my_file.txt", ios_base::in | ios_base::binary);
   mapped_file_source file( "my_file.txt" );
   filtering_streambuf< input > in;
   in.push(zlib_decompressor());
   in.push(file);
   copy(in,cout);
}

int main()
{   
   test_decoder_mmf();
   return 0;
}

In file included from /usr/local/include/boost/iostreams/operations.hpp:20:0,
                 from /usr/local/include/boost/iostreams/detail/adapter/mode_adapter.hpp:24,
                 from /usr/local/include/boost/iostreams/detail/resolve.hpp:19,
                 from /usr/local/include/boost/iostreams/detail/push.hpp:24,
                 from /usr/local/include/boost/iostreams/chain.hpp:29,
                 from /usr/local/include/boost/iostreams/filtering_streambuf.hpp:17,
                 from test_boost_iostreams2.cc:2:
/usr/local/include/boost/iostreams/optimal_buffer_size.hpp: In function ‘std::streamsize boost::iostreams::optimal_buffer_size(const T&) [with T = boost::iostreams::mapped_file_source, std::streamsize = long int]’:
/usr/local/include/boost/iostreams/chain.hpp:248:9:   instantiated from ‘void boost::iostreams::detail::chain_base<Self, Ch, Tr, Alloc, Mode>::push_impl(const T&, std::streamsize, std::streamsize) [with T = boost::iostreams::mapped_file_source, Self = boost::iostreams::chain<boost::iostreams::input, char, std::char_traits<char>, std::allocator<char> >, Ch = char, Tr = std::char_traits<char>, Alloc = std::allocator<char>, Mode = boost::iostreams::input, std::streamsize = long int]’
/usr/local/include/boost/iostreams/chain.hpp:216:1:   instantiated from ‘void boost::iostreams::detail::chain_base<Self, Ch, Tr, Alloc, Mode>::push(const T&, std::streamsize, std::streamsize, typename boost::disable_if<boost::iostreams::is_std_io<T> >::type*) [with T = boost::iostreams::mapped_file_source, Self = boost::iostreams::chain<boost::iostreams::input, char, std::char_traits<char>, std::allocator<char> >, Ch = char, Tr = std::char_traits<char>, Alloc = std::allocator<char>, Mode = boost::iostreams::input, std::streamsize = long int, typename boost::disable_if<boost::iostreams::is_std_io<T> >::type = void]’
/usr/local/include/boost/iostreams/chain.hpp:500:7:   instantiated from ‘void boost::iostreams::detail::chain_client<Chain>::push_impl(const T&, std::streamsize, std::streamsize) [with T = boost::iostreams::mapped_file_source, Chain = boost::iostreams::chain<boost::iostreams::input, char, std::char_traits<char>, std::allocator<char> >, std::streamsize = long int]’
/usr/local/include/boost/iostreams/chain.hpp:488:1:   instantiated from ‘void boost::iostreams::detail::chain_client<Chain>::push(const T&, std::streamsize, std::streamsize, typename boost::disable_if<boost::iostreams::is_std_io<T> >::type*) [with T = boost::iostreams::mapped_file_source, Chain = boost::iostreams::chain<boost::iostreams::input, char, std::char_traits<char>, std::allocator<char> >, std::streamsize = long int, typename boost::disable_if<boost::iostreams::is_std_io<T> >::type = void]’
test_boost_iostreams2.cc:17:17:   instantiated from here
/usr/local/include/boost/iostreams/optimal_buffer_size.hpp:39:55: error: ‘optimal_buffer_size’ is not a member of ‘impl {aka boost::iostreams::detail::optimal_buffer_size_impl<boost::iostreams::mapped_file_source>}’
4

1 に答える 1

4

ここに興味があるかもしれない人のために、作業コードがあります:

#include<iostream>
#include<boost/iostreams/copy.hpp>
#include<boost/iostreams/device/mapped_file.hpp>
#include<boost/iostreams/filter/zlib.hpp>
#include<boost/iostreams/filtering_streambuf.hpp>
#include<boost/iostreams/filtering_stream.hpp>
#include<boost/iostreams/stream.hpp>

using namespace std;
using namespace boost::iostreams;

void test_decoder_mmf(const std::string&filename)
{
    stream<mapped_file_source> file;
    filtering_streambuf< input > in;
    file.open(mapped_file_source(filename));
    in.push(zlib_decompressor());
    in.push(file);
    copy(in,cout);
}

int main()
{
   test_decoder_mmf("zlib-compressed-file");
   return 0;
}
于 2012-05-03T18:28:32.530 に答える