CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    117

    performance of fstream in C++

    Hi there,
    Could anyone tell me which is faster to save data with fstream---
    Situation: A line of text containing many segment are to be stored to a file, for example: Bob Is Cool.
    Methods:
    (1) Use fstream and output one word a time. Like
    out << "Bob ";
    out << "Is ";
    out << "Cool.";
    (2) Use fstream and output the whole sentence at one. Like
    out << "Bob Is Cool.";
    Which method is faster? Thanks for help.


  2. #2
    Join Date
    Apr 1999
    Posts
    48

    Re: performance of fstream in C++

    2 is likely to be faster, but there probably isn't as much difference in it as you might expect. Method 1 is unlikely to cause a disk seek on each line because in both 1 and 2 it's all memory cached until something causes the file to be flushed. So the difference is memory allocation and function call overhead, not disk hardware times.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured