2

Basically I am trying to decompress some source to the dynamically allocation memory pointed by data pointer. I have following code, I can see copy() is working, but data pointed memory is all 0s. does anyone know why?

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 );

note here data has to be a void pointer, and I have to use new operator since the data size is changing based on another indicator.

Edit: I found answer here: Setting the internal buffer used by a standard stream (pubsetbuf)

Community
  • 1
  • 1
JustDance
  • 61
  • 1
  • 5
  • Why would you convert a `float*` to a `void*` then to a `char*`? Yikes! N.B. "It has to be" is not a valid reason. Also, prefer `sizeof float` to the magic number `4`, and use some constant for the array size. – Lightness Races in Orbit Dec 15 '12 at 19:24

0 Answers0