FileStream Speed issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TheMadHatter

    FileStream Speed issue

    Yello,

    Quick Q:
    What is the fastest way of getting data from a file?
    Does the though put of the file increase if I collect
    a great big chunk of it? Eg say 6meg? or does that
    even help?

    Does a bufferedstream work better if I am just going
    to open a file and read it?

    All I am doing, is opening the file stream,
    collecting enough data for a "packet" of data,
    parcing it, then going for another packet.
    I though maybe if I collect a chunk of memory
    from the HD, the speed may improve?

    Thanks in advance.
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: FileStream Speed issue

    TheMadHatter,

    This is one of those things where you have to fine tune your code in
    response to regular conditions.

    I don't think a bufferedstream will work here because getting the bytes
    is going to be a quick operation.

    What you have to remember is that while you might decrease the number of
    file operations by reading larger chunks from the file system, you have to
    weigh that against the cost of memory allocation, which in large chunks, can
    be more detrimental than the hit you would take reading from the file
    system.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "TheMadHatt er" <TheMadHatter@d iscussions.micr osoft.com> wrote in message
    news:1A95E234-C56D-4E79-A91E-7BCC9F17A271@mi crosoft.com...[color=blue]
    > Yello,
    >
    > Quick Q:
    > What is the fastest way of getting data from a file?
    > Does the though put of the file increase if I collect
    > a great big chunk of it? Eg say 6meg? or does that
    > even help?
    >
    > Does a bufferedstream work better if I am just going
    > to open a file and read it?
    >
    > All I am doing, is opening the file stream,
    > collecting enough data for a "packet" of data,
    > parcing it, then going for another packet.
    > I though maybe if I collect a chunk of memory
    > from the HD, the speed may improve?
    >
    > Thanks in advance.[/color]


    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: FileStream Speed issue

      TheMadHatter <TheMadHatter@d iscussions.micr osoft.com> wrote:[color=blue]
      > Quick Q:
      > What is the fastest way of getting data from a file?
      > Does the though put of the file increase if I collect
      > a great big chunk of it? Eg say 6meg? or does that
      > even help?[/color]

      In my experience it helps a very small amount (and only in some tests).
      I would suggest a buffer size of about 16 or 32K usually. That way it's
      definitely not on the large object heap, but can store a fair chunk of
      data.

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      If replying to the group, please do not mail me too

      Comment

      Working...