473,563 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Efficiently reading bytes from a FileStream

I create a new filestream and then i move i use the readbyte function
and the position function when required. These seem to be cripplingly
slow for some reason. This readbyte maybe is the problem. Do i need to
use a binaryReader with this in order for it to be faster?. I am
manipulating a compressed image file. Because i am reading in so many
bytes it makes it inefficient. Could somebody have a suggestion as how
to remedy this problem.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
3 2275
You should use the Stream.Read function, reading blocks of at least a few
thousand bytes at a time. System calls take time. Using one per byte *is*
cripplingly slow. If you really want to use the "readbyte" function, use a
System.IO.Buffe redStream. This will at least buffer the system calls - but
you would still have one method call per byte.

Niki

"James Dean" <m_*******@yaho o.com> wrote in
news:ub******** ******@TK2MSFTN GP12.phx.gbl...
I create a new filestream and then i move i use the readbyte function
and the position function when required. These seem to be cripplingly
slow for some reason. This readbyte maybe is the problem. Do i need to
use a binaryReader with this in order for it to be faster?. I am
manipulating a compressed image file. Because i am reading in so many
bytes it makes it inefficient. Could somebody have a suggestion as how
to remedy this problem.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
Try Jon's code and explanation:

http://www.yoda.arachsys.com/csharp/readbinary.html

--
Scott
http://www.OdeToCode.com

On Tue, 06 Jul 2004 02:05:07 -0700, James Dean <m_*******@yaho o.com>
wrote:
I create a new filestream and then i move i use the readbyte function
and the position function when required. These seem to be cripplingly
slow for some reason. This readbyte maybe is the problem. Do i need to
use a binaryReader with this in order for it to be faster?. I am
manipulating a compressed image file. Because i am reading in so many
bytes it makes it inefficient. Could somebody have a suggestion as how
to remedy this problem.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #3
Hey i used the function that he recommended in that page you gave me. I
just want to say thanks alot it has really helped enormously..... .

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2534
by: Jón Sveinsson | last post by:
Hello everyone I have been able to read data from binary files to filestrean, the data in the files are structured, what I'm trying to do is to loop through the binary files and add data to my struct, in this file there are lot of records i need to loop trough, first time I read the file, the data is fine but for the rest the data is not...
4
12792
by: Erpman | last post by:
I am trying to access the data with in a wav file. I am testing with very small files in order to keep the code simple to start with. Basically, im writing the entire wav file to a byte using a fileStream. The problem is that when reading back the data word by word and printing the results on a general form, once the data chunk header has...
4
3277
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any errors. After reading the ole object from db, I saved it to C: as file1.bmp and displayed on the web. But it can not be displayed. After I manually sent...
1
2088
by: Ken | last post by:
Hello, I'm trying to read a Blob from Oracle and then write it to an audio file(.AU). I'm using Visual Studio.Net 2003 (VB). I can't seem to get my code to work. Will someone take a look at it and tell me what am I doing wrong. Any help would be appreciated. Thanks Dim Conn As OracleConnection = New OracleConnection("data...
0
1304
by: Ken | last post by:
Hello, I'm trying to read a Blob from Oracle and then write it to an audio file(.AU). I'm using Visual Studio.Net 2003 (VB). I can't seem to get my code to work. Will someone take a look at it and tell me what am I doing wrong. Any help would be appreciated. Thanks Dim Conn As OracleConnection = New OracleConnection("data...
2
1837
by: Mad Scientist Jr | last post by:
i'm trying to read a file byte by byte (and later alter the data and write it to a 2nd file byte by byte) and running into a problem where it seems to keep reading the same byte over and over again (an endless loop). i thought that BinaryReader.ReadByte advanced to the next byte? i had it time out after 1000 iterations, and keeps outputting...
3
3587
by: Yehia A.Salam | last post by:
Hello, I am trying to read from an xml file and put it to a memory stream so I can read it multiple times from the beginning using XmlTextReader without accessing the harddisk , I tried using FileStream but it locked the xml file so I can't access it anymore until I close the filestream, so my question is how to read from the file to the...
11
2308
by: Gina_Marano | last post by:
Hey all, I need to validate a large binary file. I just need to read the last 100 or so bytes of the file. Here is what I am currently doing but it seems slow: private bool ValidFile(string afilename) { byte ch;
3
6988
by: Jon Harrop | last post by:
I can read bytes from a FileStream with stream.ReadByte() but that does not handle stdin. I can read from stdin with System.Console.In using reader.Read() but it is 6x slower. So how do I read bytes from stdin efficiently? -- Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u
0
7659
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7580
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8103
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7945
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3634
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2079
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.