Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fastest method of writing to a file 2

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
US
Hello,
I am going to be writing a large amount of data in the form of a very large character array to a text file. What is the fastest way to do this, as speed will be very important?
Thankyou
 
Well if your array already contains newlines (as if you had read the whole file into memory in one go), then look at either write() or fwrite()

[tt]ssize_t write(int fd, const void *buf, size_t count);
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
[/tt]

--
 
In case of (portable) stream i/o fwrite() using don't forget to set larger buffer size with
Code:
setvbuf(stream,0,_IOFBF,bufsize);
after fopen() before 1st fwrite().
It seems on Windows the best way will be CreateFile/WriteFile API using.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top