码迷,mamicode.com
首页 > 移动开发 > 详细

使用boost的mapped file

时间:2015-01-07 16:48:59      阅读:549      评论:0      收藏:0      [点我收藏+]

标签:mapped_file_source   mapped_file_params   mapped_file_sink   

#include <boost/iostreams/device/mapped_file.hpp>
std::string src_path = "/Users/alex/Movies/m3u8_videos/dance.mp4";
std::string dst_path = "/Users/alex/Movies/m3u8_videos/dance-copy.mp4";
void copy_file()
{
	boost::iostreams::mapped_file_params  params_src;
	params_src.path = src_path;
	boost::iostreams::mapped_file_source  mf_src;
	mf_src.open(params_src);
	if(mf_src.is_open())
	{
		unsigned char* p_src = (unsigned char*)mf_src.data();
		size_t len_src = mf_src.size();
		
		boost::iostreams::mapped_file_params  params_dst;
		params_dst.path = dst_path;
		params_dst.new_file_size = len_src;
		boost::iostreams::mapped_file_sink  mf_dst;
		mf_dst.open(params_dst);
		if(mf_dst.is_open())
		{
			unsigned char* p_dst = (unsigned char*)mf_dst.data();
			for(size_t i = 0; i < len_src ; i++)
			{
				*(p_dst + i) = *(p_src + i);
			}
			mf_dst.close();
		}
		mf_src.close();
	}
}
int main()
{
<span style="white-space:pre">	</span>copy_file();
<span style="white-space:pre">	</span>return 0;
}


使用boost的mapped file

标签:mapped_file_source   mapped_file_params   mapped_file_sink   

原文地址:http://blog.csdn.net/dotphoenix/article/details/42495279

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!