473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 2270
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.BufferedStream. This will at least buffer the system calls - but
you would still have one method call per byte.

Niki

"James Dean" <m_*******@yahoo.com> wrote in
news:ub**************@TK2MSFTNGP12.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_*******@yahoo.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
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...
4
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...
4
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...
1
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...
0
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...
2
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...
3
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...
11
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.