kaspar_silas
June 2nd, 2010, 12:27 PM
Hi all,
Hopefully someone can shine some light on this. The following is a short code demo. It sets up three arrays. A large static one, a small dynamic one and a big dynamic one. When I try to write these out it always fails on the big array. Hence the output is:
250000
300000
-1
and the produced file varies in size around 560000 bytes.
So why is the big array failing mid write? I can even put a loop around the small array and run it so that it writes out the same data. Is there limit on the maximum array that be cast or wrote in one block?
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc,char* argv[] )
{
//Binary write file
ofstream OUT( "TESTY.bin" , ios::out | ios::binary);
char sbuf[250000];
for(int i=0;i<250000;i++)sbuf[i]=0;
//Make small Dynamic Buffer
short* sdbuf=new short[25000];
for(unsigned long i=0;i<25000;i++)sdbuf[i]=0;
//Make Dynamic Buffer
short* dbuf=new short[250000];
for(unsigned long i=0;i<250000;i++)dbuf[i]=0;
//Make Static Buffer
//Binary writing
OUT.write( sbuf, sizeof(sbuf) );
cout<<OUT.tellp()<<endl;
OUT.write( (char*) &sdbuf, 25000*sizeof(short) );
cout<<OUT.tellp()<<endl;
OUT.write( (char*) &dbuf, 250000*sizeof(short) )<<endl;
cout<<OUT.tellp()<<endl;
//Tidy up
OUT.close();
if(sdbuf){delete[]sdbuf;sdbuf=0;}
if(dbuf){ delete[]dbuf; dbuf=0;}
return 0;
}
Hopefully someone can shine some light on this. The following is a short code demo. It sets up three arrays. A large static one, a small dynamic one and a big dynamic one. When I try to write these out it always fails on the big array. Hence the output is:
250000
300000
-1
and the produced file varies in size around 560000 bytes.
So why is the big array failing mid write? I can even put a loop around the small array and run it so that it writes out the same data. Is there limit on the maximum array that be cast or wrote in one block?
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc,char* argv[] )
{
//Binary write file
ofstream OUT( "TESTY.bin" , ios::out | ios::binary);
char sbuf[250000];
for(int i=0;i<250000;i++)sbuf[i]=0;
//Make small Dynamic Buffer
short* sdbuf=new short[25000];
for(unsigned long i=0;i<25000;i++)sdbuf[i]=0;
//Make Dynamic Buffer
short* dbuf=new short[250000];
for(unsigned long i=0;i<250000;i++)dbuf[i]=0;
//Make Static Buffer
//Binary writing
OUT.write( sbuf, sizeof(sbuf) );
cout<<OUT.tellp()<<endl;
OUT.write( (char*) &sdbuf, 25000*sizeof(short) );
cout<<OUT.tellp()<<endl;
OUT.write( (char*) &dbuf, 250000*sizeof(short) )<<endl;
cout<<OUT.tellp()<<endl;
//Tidy up
OUT.close();
if(sdbuf){delete[]sdbuf;sdbuf=0;}
if(dbuf){ delete[]dbuf; dbuf=0;}
return 0;
}