Why is write of ofstream so slow?

Giganews Newsgroups
Subject: Why is write of ofstream so slow?
Posted by:  Ananya
Date: Wed, 4 Jul 2007

I am writing the pixels of an image to a file.  I have

const char *charpixels = ...
ofstream pixelFile;
pixelFile.open("pixels.dat", ios::binary);
pixelFile.write(charpixels, count);

For a large image (count is about 30 million), the write takes about 4
seconds.  Why is it so slow?  Can it be made faster?

Replies