Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

C++ program runs slow in VS2008

12 like 0 dislike
have a program written in C++, that opens a binary file(test.bin), reads it object by object, and puts each object into a new file (it opens the new file, writes into it(append), and closes it). I use fopen/fclose, fread and fwrite. test.bin contains 20,000 objects.

This program runs under linux with g++ in 1 sec but in VS2008 in debug/release mode in 1min!

There are reasons why I don't do them in batches or don't keep them in memory or any other kind of optimizations.

I just wonder why it is that much slow under windows.

Thanks,
asked 2 years ago by DBA-boss (120,990 points)

1 Answer

0 like 0 dislike
Unfortunately file access on Windows isn't renowned for its brilliant speed, particularly if you're opening lots of files and only reading and writing small amounts of data. For better results, the (not particularly helpful) solution would be to read large amounts of data from a small number of files. (Or switch to Linux entirely for this program?!)

Other random suggestions to try:

turn off the virus checker if you have one (I've got Kaspersky on my PC, and writing 20,000 files quickly drove it bananas)
use an NTFS disk if you have one (FAT32 will be even worse)
make sure you're not accidentally using text mode with fopen (easily done)
use setvbuf to increase the buffer size for each FILE
try CreateFile/ReadFile/etc. instead of fopen and friends, which won't solve your problem but may shave a few seconds off the running time (since the stdio functions do a bit of extra work that you probably don't need)
answered 2 years ago by eagles11 (179,830 points)

Related questions

14 like 0 dislike
0 answers
11 like 0 dislike
1 answer
asked 2 years ago by DBA-boss (120,990 points)
12 like 0 dislike
0 answers
7 like 0 dislike
0 answers
0 like 0 dislike
0 answers
asked 1 year ago by anonymous