Results 1 to 7 of 7

Thread: [RESOLVED] Why is reading a File in chunks quicker than in one go?

  1. #1

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,664

    Resolved [RESOLVED] Why is reading a File in chunks quicker than in one go?

    Hello,

    I stumbled upon something that's making me think now..

    Previously, the program was Loading chunks from the files by
    opening them as Binary, and reading chunks off:
    Code:
    Get #fFile, xPos + 1, RAMBuffer
    This was pretty fast. 90 files took 5 secs to load.

    But the problem was, since its using the Native OPEN statement it doesn't seem to handle Unicode paths.
    So if a user is using German, Chinese Windows etc... the Path to the File would contain Unicode, hence error!

    So I thought, why don't I instead Load the File all at Once [via CreateFile] in to a String Buffer and then using mid$() to split chunks out to strings. Now this takes almost 3x the time 16 seconds to complete :/


    I thought doing things in Memory should be quicker than reading off of the HD in a loop ?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,543

    Re: Why is reading a File in chunks quicker than in one go?

    Hmmm... I'd be willing to bet it's the use of mid$() that's actually the problem, not the reading chunks vs whole file. String manipulation in general is always slower (your first snip insinuates binary access, the second indicates string manipulations). And it has more to do with how string manipulation happens - they're immutable, which means in order to change a string, a new memory area needs to be allocated, and the string copied. A Byte-based buffer on the other hand doesn't have that limitation.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,664

    Re: Why is reading a File in chunks quicker than in one go?

    OMG...

    Having done further tests, I can now confirm that the delay lays not with the MID function, but I had a Single instr check which seemed to be taking ages as it used to do a binary comparison. Having changed it to a textcomparison it's all super quick now even faster than the previous Binary version From 5 secs down to less than a second
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] Why is reading a File in chunks quicker than in one go?

    That doesn't sound quite right either. Binary comparison should be far faster than text comparison. With binary comparison, either byte equality exist or not. For text comparison, byte can bet this or that or maybe this other thing. I'd guess that looping and/or loading bytes into strings (vice versa) may be the bottleneck.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,664

    Re: [RESOLVED] Why is reading a File in chunks quicker than in one go?

    Yes, binary comparison should be faster than text, but if the compared input is of Binary ?

    Well, I literally analysed it line by line and even skipping WHOLE chunk so it goes alll the way to the end of the loop to check speeds with Gettickcount and skipping all mid() functions literally had no effect on speed, until the instr() call.

    As soon as changing
    Code:
    FPos = InStr(1, strGetNames, "RFG", vbBinaryCompare)
    to
    FPos = InStr(1, strGetNames, "RFG")
    Everything is super fast
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: [RESOLVED] Why is reading a File in chunks quicker than in one go?

    vbBinaryCompare is the default so you did not really change anything

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] Why is reading a File in chunks quicker than in one go?

    For all we know he managed to get something called "vbBinaryCompare" defined with a non-zero value. Probably as a side-effect of not using Option Explicit.

Tags for this Thread

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