|
-
December 30th, 2006, 07:29 PM
#1
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
-
December 31st, 2006, 06:59 AM
#2
Re: FileStream + LargeFiles
 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 
-
December 31st, 2006, 09:02 AM
#3
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.
-
December 31st, 2006, 10:23 AM
#4
Re: FileStream + LargeFiles
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|