CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Speed up reading

    I have this program that does some encoding. The program needs about 20 seconds to encode a file about 8 megs.
    Of those 20 seconds, it takes about 3 seconds to encode the file. The remaining time is used by the reading of the file.
    What I was wondering is that if there is a faster way to read the data. I'm reading the data into a string, that I then convert to a bytearray.
    This is the code I use to do that

    Open "somefile" for binary access read as #ffile
    strInput = input(FileLen("somefile"),#ffile)
    arrInput = StrConv(strInput,vbFromUnicode)




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Speed up reading

    Will reading directly into a byte array make it faster?

    Dim FileAsByte() as Byte
    FileHandle = FreeFile
    Open sFileName for binary as FileHandle
    ReDim FileAsByte(LOF(FileHandle))
    get FileHandle, , FileAsByte





  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Speed up reading

    Man, I didn't know Get was that much faster as Input. It takes about 200 ms to read the entire file (about 2.5 megs) into memory. I guess it is because i'm not going via strings any more. I tried doing it with input, reading the entire file into a byte array, but the problem there was that it was reading Unicode, giving me an array twice as big, with an empty (Null) byte after each other one. Even then it was slow like hell.


    Thanx a lot!

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Great!

    Too bad I already finished my votes...

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Conversions

    I found out conversion operations (from byte to String and so on) and string manipulations (using Mid$, Left$, Right$,...) slow down a lot.

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured