Reading in File, VB is so slow!! Please help? 
Author Message
 Reading in File, VB is so slow!! Please help?

Please help I've searched everywhere for a faster routine to read in a file!

I need to read in a file and convert each byte read into it's hex equivalent
then display the file (Hex format) in a textbox:-

I open the file as binary and read in 1 byte at a time then convert it to
hex using Hex$(currentbyte) then add it to a string.  The string will then
hold e.g. "A34AF431DB2A" etc..  Then I copy the string into a textbox.

This is painfully slow and I can't figure out a way of reading in the file
and converting to hex any faster!

It's basically for a hex editor program I'm trying to write.  There must be
another way of doing this, perhaps with the API?

Thanks in advance for any ideas!

James



Sat, 04 Aug 2001 03:00:00 GMT  
 Reading in File, VB is so slow!! Please help?
Why don't you read big blocks from disk in memory and then process it. The
weakest part in u'r strategy is disk i/o.
Prasad

Quote:

>Please help I've searched everywhere for a faster routine to read in a
file!

>I need to read in a file and convert each byte read into it's hex
equivalent
>then display the file (Hex format) in a textbox:-

>I open the file as binary and read in 1 byte at a time then convert it to
>hex using Hex$(currentbyte) then add it to a string.  The string will then
>hold e.g. "A34AF431DB2A" etc..  Then I copy the string into a textbox.

>This is painfully slow and I can't figure out a way of reading in the file
>and converting to hex any faster!

>It's basically for a hex editor program I'm trying to write.  There must be
>another way of doing this, perhaps with the API?

>Thanks in advance for any ideas!

>James




Wed, 08 Aug 2001 03:00:00 GMT  
 Reading in File, VB is so slow!! Please help?
James,

From your description, it sounds like you are reading byte by byte and
appending each converted byte to a string.  There are two potential
bottlenecks here:

  1) Reading byte by byte and processing each is going to cause a lot of
unnecessary disk access.  Try reading in a larger block at a time.  Maybe
256k each block.

  2) Appending to a string is a tremendous strain on resources.  Each time
you append a byte to a string, VB must: a) determine how long the resulting
string will be; b) allocate a block of memory in which to store it; c and d)
copy both strings to the new block of memory.

NUMBER 2 IS KILLING YOU!

Your best bet is to determine how long the resulting string needs to be.
Each byte will require two characters in hex.  Then you want to adjust the
bytes in your string rather than appending new ones.  Do something like
this:

Const lBufferLen as Long = 255&
Dim sHexString as String
Dim sBuffer as String * lBufferLen
Dim lPos as Long

' Prime sHexString with null characters
sHexString = String$(vbnullstring, lBufferLen*2)

For lPos = 1 to lBufferLen
  Mid$(sHexString, (lPos-1)*2+1) = Hex$(Asc(Mid$(sBuffer,lPos,1)))
Next lPos

Quote:

>I need to read in a file and convert each byte read into it's hex
equivalent
>then display the file (Hex format) in a textbox:-

>I open the file as binary and read in 1 byte at a time then convert it to
>hex using Hex$(currentbyte) then add it to a string.  The string will then
>hold e.g. "A34AF431DB2A" etc..  Then I copy the string into a textbox.

>James




Fri, 10 Aug 2001 03:00:00 GMT  
 Reading in File, VB is so slow!! Please help?
Thanks this is great!  Much faster!  :)


Sat, 11 Aug 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Slow file reading using binary methods HELP PLEASE!

2. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

3. (urgent - please help) reading and writing in a text file using VB

4. (urgent - please help) reading and writing in a text file using VB

5. Please, please help - VB6 opening and reading a project mpp file

6. HELP -too slow performance of reading Excel-sheetcontents into VB 5.0

7. reading and parsing file slows down for large files

8. vb help please i am close to a nervous breakdown

9. Please help..VB setup wizard....very slow?

10. Please, please help, I am desperated...:(

11. PLEASE, PLEASE HELP, am I going MAD - Generating Totals

12. Please help with reading code from an external file

 

 
Powered by phpBB® Forum Software