Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-03-2006, 02:01 PM   #1
LQ Newbie
Registered: Aug 2006
Posts: 4

Rep: Reputation: 0
Angry Slow file writing with 'fwrite' function in C-code...

First of all, I am not sure if this problem comes from the OS or Hardware or even my program.
Anyway, when I execute a simple C-code which is doing some processing and writes the results
into the hard disc, the program takes too much time to finish up the file writing. The file size is about 450MB. I am using 'fwrite' function which is normally working well in elsewhere but in our new computer ( workstation which has 4 CPUs and each is dure core), it shows really slow file writing. It take a couple of minitues to finish up the writing. Sometimes, when I slightly change my code (Definiely, other parts which is not related with this writing module), it is fast ( done within a few secs).

Any one has same problem ? or Any idea will be reall appreciated.

Last edited by scho; 08-03-2006 at 02:13 PM.
Old 08-04-2006, 07:06 AM   #2
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
Old 08-04-2006, 07:09 AM   #3
Senior Member
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
are you reading from and writing to a disk? perhaps adding or increasing the buffers of your reading and writing will speed-up the operation.

Last edited by konsolebox; 09-23-2006 at 06:13 AM.
Old 08-04-2006, 07:11 AM   #4
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
It is hard to say why, but my suggestion is to run strace on your program. This could give you an idea of what exactly it is doing when it slows down.
Old 08-04-2006, 07:13 AM   #5
Senior Member
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
The file size is about 450MB.
There's your answer.

It depends on a lot of things. Without the code and without knowing what the background processes are, where and how you call the fwrite function, we can only guess as to why your code is slow.
Old 08-07-2006, 12:42 AM   #6
Registered: Oct 2004
Location: India
Distribution: Redhat
Posts: 88

Rep: Reputation: 15
Since by changing code in "other parts", you are able to speed up, it could be your "some processing" which is taking up time, may be rightly so too. I think you should post code, without which no one can point the exact problem.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
php code not writing or working? ati Programming 4 05-11-2006 07:51 AM
writing a script to perform a function on each users mail folder jhill Linux - Newbie 2 08-24-2004 07:18 AM
error function in c code shams Programming 3 08-06-2004 04:00 AM
C code for killall function Linh Programming 3 08-01-2003 11:34 PM
What is correct code for "Include File Function" on .asp pages gregoryfrancis Linux - General 1 02-11-2003 10:49 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration