title: in-memory FILE* (without disk access)
body: <p>We have library which accepts FILE* (CImg). For performance reason we wish to handle data already in memory without accessing a disk. Target platform is windows which unfortunately does not support fmemopen (and funopen)</p>
  
  <pre><code>char* buf = new char[sz];
  
  FILE *fp = fopen("C:\\test.dat", "wb");
  int r = setvbuf(fp, buf, _IOFBF, sz);
  
  r = fwrite(src_buf, 1, sz, fp);     // Here r contains right size
  
  
  fseek(fp, 0, SEEK_END);
  size_t sz2 = ftell(fp);             // sz2 contains right size as well
  rewind(fp);
  
  // Test (something like this actually is somewhere deep inside library)
  char* read_buf = new char[sz];
  r = fread(read_buf, 1, sz, fp);     // Zero!
  </code></pre>
  
  <p>Final fread() can't read anything... Any suggestions?</p>