如何将数据解压缩到动态分配的内存位置

时间:2012-12-11 05:46:48

标签: c++ boost gzip iostream boost-iostreams

基本上我试图将一些源解压缩到数据指针指向的动态分配内存。我有以下代码,我可以看到copy()正在运行,但数据指向的内存全是0s。有谁知道为什么?

void *data = new float[1000000]();
std::ostringstream dest;
dest.rdbuf()->pubsetbuf((char *)data,1000000*4);
boost::iostreams::array_source source( some source );
boost::iostreams::filtering_istreambuf in;
boost::iostreams::filtering_ostreambuf out;
in.push( ios::gzip_decompressor() );
in.push( source );
out.push( dest );
boost::iostreams::copy( in, out );

注意这里的数据必须是一个无效指针,我必须使用new运算符,因为数据大小正在根据另一个指标发生变化。

编辑:我在这里找到答案:Setting the internal buffer used by a standard stream (pubsetbuf)

0 个答案:

没有答案
相关问题