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

    FileStream + LargeFiles

    Hello All,

    I am semi-new to C# and .NET, I am using MS VS 2005 (.NET 2.0)


    I am trying to write a program that writes data to a file (a large file in chunks of 512K). The files could potentially be bigger than 2Gigs.

    Problem #1: I have heard FileStream is not as efficient as using StreamWriter, is this true? how would i optimize the buffers to maximize performance.

    Problem #2: I have not tested this yet, but I am pretty sure this is going to be a problem. In C#, an int is 2^32 or (approx 2Gigs). I am using FileStream.Write (byte[] array, int offset, int count) where offset and count are integers. Does this mean I can not write beyond 2gigs?

    Thanks

  2. #2
    Join Date
    Jul 2006
    Posts
    97

    Re: FileStream + LargeFiles

    Quote Originally Posted by aznium
    Does this mean I can not write beyond 2gigs?
    Thanks
    Hi!
    Sorry, but I cannot help you with the first problem.

    As for the second, it doesn't mean that you can't write more than 2gigs into the file, it only means that you can't write arrays bigger than 2^32 entries.
    You are writing the data in chunks, so just seek to the end of file and write chunk of data.
    Using .NET 2.0

  3. #3
    Join Date
    Jan 2003
    Posts
    615

    Re: FileStream + LargeFiles

    FileStream objects support random access to files using the Seek method. Seek allows the read/write position to be moved to any position within the file. This is done with byte offset reference point parameters. The byte offset is relative to the seek reference point, which can be the beginning, the current position, or the end of the underlying file, as represented by the three properties of the SeekOrigin class.
    MSDN
    Last edited by laasunde; December 31st, 2006 at 09:06 AM.

  4. #4
    Join Date
    Apr 2005
    Posts
    16

    Re: FileStream + LargeFiles

    Quote Originally Posted by gecka
    Hi!
    Sorry, but I cannot help you with the first problem.

    As for the second, it doesn't mean that you can't write more than 2gigs into the file, it only means that you can't write arrays bigger than 2^32 entries.
    You are writing the data in chunks, so just seek to the end of file and write chunk of data.

    your idea to write to end of file is great, thanks . but i forgot to mention, the chunks of data may not arrive sequentially . i need random access . however, the seek method uses long and i can position the write point any where in the file.

    thanks a lot

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