I just noticed that the Stream class has a Seek method, which implies that a
FileStream object can be used to manipulate a random-access file. Before
now, I assumed that a Stream, as its name implies, could only stream
sequential data.
Are there any advantages / disadvantages to using a FileStream to manage a
random access file, as opposed to using FileOpen, FilePut, and FileGet? I am
thinking specifically about performance advantages -- is the FileStream
efficient at jumping from point to point in a file?
-TC 5 8353
In article <8fQqc.33140$bS1.10862@okepread02>, TC wrote: I just noticed that the Stream class has a Seek method, which implies that a FileStream object can be used to manipulate a random-access file. Before now, I assumed that a Stream, as its name implies, could only stream sequential data.
Are there any advantages / disadvantages to using a FileStream to manage a random access file, as opposed to using FileOpen, FilePut, and FileGet? I am thinking specifically about performance advantages -- is the FileStream efficient at jumping from point to point in a file?
-TC
All of the native streams are faster then the FileXXX funtions. The
problem comes in calculating the offset - since you can't use fixed size
structures ;)
--
Tom Shelton [MVP]
Tom,
That is odd. Before you mentioned that limitation, I had observed that
VB.NET offers many more operations on streams than it does on files opened
with FileOpen. But you are right; BinaryWriter cannot write a variable of a
fixed-length structure, even though FilePut can. Do you think there is a
good reason for this discrepancy? Or do you suppose it was an oversight?
-TC
"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:uP*************@tk2msftngp13.phx.gbl... All of the native streams are faster then the FileXXX funtions. The problem comes in calculating the offset - since you can't use fixed size structures ;)
-- Tom Shelton [MVP]
TC,
If I needed to write a structure to a BinaryWriter I would simply implement
a form of binary serialization that wrote to or read from a BinaryStream,
similar to the technique discussed in the following article. http://msdn.microsoft.com/library/de...rp09182003.asp
The example is in C#, however it should be easily converted to VB.NET, post
if you need help.
Remember in .NET it is very hard to get a 'fixed-length structure' where
that structure includes a String, as strings by definition are variable
length! (as they are objects). VB.NET supports fixed-length strings via an
attribute.
Also seeing as normal .NET Binary Serialization supports serializing any
..NET Class or Structure of any size or shape, it would IMHO be
duplication...
Hope this helps
Jay
"TC" <v@x.z> wrote in message news:eKTqc.33326$bS1.15129@okepread02... Tom,
That is odd. Before you mentioned that limitation, I had observed that VB.NET offers many more operations on streams than it does on files opened with FileOpen. But you are right; BinaryWriter cannot write a variable of
a fixed-length structure, even though FilePut can. Do you think there is a good reason for this discrepancy? Or do you suppose it was an oversight?
-TC
"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message news:uP*************@tk2msftngp13.phx.gbl... All of the native streams are faster then the FileXXX funtions. The problem comes in calculating the offset - since you can't use fixed size structures ;)
-- Tom Shelton [MVP]
Jay,
Thank you for the suggestion. Actually, my last post was misleading -- In my
current project, I do not need to store fixed-length structures. I was
merely responding to Tom's comment about structures, which was deserving of
thought.
In fact, my current project deals with fixed-length binary objects. I should
have no trouble writing them to a stream with the BinaryWriter.Write(
Byte() ) method. I'm trying to stay away from serialization because it isn't
compatible with random-access storage, and simply serializing everything in
one sequential file, while easy to code, doesn't support the data-retrieval
speed I require.
Take it easy.
-TC
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:O6**************@TK2MSFTNGP11.phx.gbl... TC, If I needed to write a structure to a BinaryWriter I would simply
implement a form of binary serialization that wrote to or read from a BinaryStream, similar to the technique discussed in the following article.
http://msdn.microsoft.com/library/de...rp09182003.asp The example is in C#, however it should be easily converted to VB.NET,
post if you need help.
Remember in .NET it is very hard to get a 'fixed-length structure' where that structure includes a String, as strings by definition are variable length! (as they are objects). VB.NET supports fixed-length strings via an attribute.
Also seeing as normal .NET Binary Serialization supports serializing any .NET Class or Structure of any size or shape, it would IMHO be duplication...
Hope this helps Jay
"TC" <v@x.z> wrote in message news:eKTqc.33326$bS1.15129@okepread02... Tom,
That is odd. Before you mentioned that limitation, I had observed that VB.NET offers many more operations on streams than it does on files
opened with FileOpen. But you are right; BinaryWriter cannot write a variable
of a fixed-length structure, even though FilePut can. Do you think there is a good reason for this discrepancy? Or do you suppose it was an oversight?
-TC
"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message news:uP*************@tk2msftngp13.phx.gbl... All of the native streams are faster then the FileXXX funtions. The problem comes in calculating the offset - since you can't use fixed
size structures ;)
-- Tom Shelton [MVP]
TC,
I realize you were did not ask the original question, however I was
answering your questions: Do you think there is a good reason for this discrepancy? Or do you suppose it was an
oversight?
The "good reason" is binary serialization, so no it is not an oversight.
Hope this helps
Jay
"TC" <v@x.z> wrote in message news:shUqc.33529$bS1.3556@okepread02... Jay,
Thank you for the suggestion. Actually, my last post was misleading -- In
my current project, I do not need to store fixed-length structures. I was merely responding to Tom's comment about structures, which was deserving
of thought.
In fact, my current project deals with fixed-length binary objects. I
should have no trouble writing them to a stream with the BinaryWriter.Write( Byte() ) method. I'm trying to stay away from serialization because it
isn't compatible with random-access storage, and simply serializing everything
in one sequential file, while easy to code, doesn't support the
data-retrieval speed I require.
Take it easy. -TC
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:O6**************@TK2MSFTNGP11.phx.gbl... TC, If I needed to write a structure to a BinaryWriter I would simply implement a form of binary serialization that wrote to or read from a
BinaryStream, similar to the technique discussed in the following article.
http://msdn.microsoft.com/library/de...rp09182003.asp The example is in C#, however it should be easily converted to VB.NET,
post if you need help.
Remember in .NET it is very hard to get a 'fixed-length structure' where that structure includes a String, as strings by definition are variable length! (as they are objects). VB.NET supports fixed-length strings via
an attribute.
Also seeing as normal .NET Binary Serialization supports serializing any .NET Class or Structure of any size or shape, it would IMHO be duplication...
Hope this helps Jay
"TC" <v@x.z> wrote in message news:eKTqc.33326$bS1.15129@okepread02... Tom,
That is odd. Before you mentioned that limitation, I had observed that VB.NET offers many more operations on streams than it does on files opened with FileOpen. But you are right; BinaryWriter cannot write a variable of a fixed-length structure, even though FilePut can. Do you think there is
a good reason for this discrepancy? Or do you suppose it was an
oversight? -TC
"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message news:uP*************@tk2msftngp13.phx.gbl... > > All of the native streams are faster then the FileXXX funtions. The > problem comes in calculating the offset - since you can't use fixed size > structures ;) > > -- > Tom Shelton [MVP]
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark Miller |
last post by:
I have a char array and when I write it to a file using BinaryWriter the
position of the pointer is the size of the array + 1. For example: writing
char leaves the pointer at position 26 after...
|
by: Bonj |
last post by:
I downloaded the gzlib library from zlib in order to do compression.
(http://www.gzip.org/zlib)
The prototype of the compression function seems to be
int compress (Bytef *dest, uLongf *destLen,...
|
by: Gidi Morris via .NET 247 |
last post by:
Hi,
Is there a way to play audio using MCI (I preffer MCI, but if you know of any others I'll be greatful) from a Filestream?
I mean, I have a filestream to an audio file, can I play the audio?...
|
by: John |
last post by:
Hi
I need to be able to call a web service method, receive the dataset that web
method returns and store it in an access table. My problem is that I don't
know how to "receive" a complex type...
|
by: Aji Mathews via .NET 247 |
last post by:
Hi
I am using SharpZipLib. Could someone help with some sample code to unzip a file to a specified location.
Thanks
--------------------------------
From: Aji Mathews
...
|
by: JDeats |
last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting
and decrypting a file.
http://support.microsoft.com/kb/307010
In .NET 2.0 this approach is not fully supported (a .NET 2.0...
|
by: Peter |
last post by:
Hi
I will use a Random Access File in dotnet/csharp. The file is created
with Visual Basic 6 (VB6).
My Problem is to find out the corresponding Types I had to use in
dotnet - reading the VB6...
|
by: stumorgan |
last post by:
I'm doing some USB communications in C# and am running into a minor
annoyance. I'm using the Windows API CreateFile function to get a
SafeFileHandle, which I then stuff into a FileStream and from...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |