How to speed-up access to strings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32661

    #61
    Originally posted by SioSio
    SioSio:
    Memory manipulation using the API was 300 times faster than using strings
    That really depends on what is meant by "using strings". If that refers to recreating massive strings every time a small change is made - and thus doing so millions of times for each string - then yes. I can see that almost anything would be.

    You should remember that, even if API string manipulation took absolutely no time at all within the API code - which is clealy impossible but to deal with this hypothetically we'll assume such for now, then it would still be unlikely to perform too well as you will still have the overhead of setting up the API call and calling the procedure. Every parameter is at least one Push onto the stack and must at least readjust the stack pointer (SP Register) once it's finished. Not too considerable perhaps when compared with ordinary VBA code (which is only semi-compiled anyway) but it all adds up when dealing with such massive strings.

    NB. Rabbit touched on this also but Bytes are 8 bits in all circumstances. If/when you need to deal with Unicode characters then you'd need to work with them as Longs and not Bytes.

    All that said, there's no need to apologise. The OP (Ricardo) did specifically ask for help in that area too. It seems very unlikely it would give him what he requires - the fastest way to manipulate large files - but answering his question (or even just trying to) is always valid.

    Comment

    • SioSio
      Contributor
      • Dec 2019
      • 272

      #62
      I wrote "using strings" is Ricardo's original code, and "300 times" is when processing 20MByte strings. API used "CopyMemory ".

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #63
        Hi SioSio.

        I know this isn't your question, as such, but I'm keen that you understand why we are generally trying to encourage Ricardo to avoid the idea of using Windows API procedures for this task. They have their place, certainly. This is not one of them - as I think has been explained very fully and clearly in the preceding posts. I hope you understand. I struggle to understand some of what you post so I'm not sure that you do yet - but as I say - that is my inability to understand you.
        Originally posted by SioSio
        SioSio:
        AIP (API?) used "CopyMemory ".
        I trust you don't imagine that would lead to quick code. Every time a string is copied in VBA the "CopyMemory " process is used. What is needed to boost performance is to make the updates in-place rather than making a new copy elsewhere with the changes reflected in the new copy. Thus why Rabbit's Byte Array or the more standard Mid() on the left of the assignment is what has been recommended. Either of these approaches will perform faster than using an API procedure to perform the updates. Again, all explained already in earlier posts.

        Comment

        • Ricardo de Mila
          New Member
          • Jan 2011
          • 41

          #64
          Hello Rabbit and everybody else.
          Thank you very much for the valuable support.
          In the next days, I will try to test your code to try to meassure time differences.
          Your code is very clear and appears to be a very nice solution for me.

          It seems you gave the best answer for this question, But I really don't know how to mark it as "the best answer".
          I feel this has been already done. Not sure.

          Any way...
          I will try to have an answer for that as soon as possible.
          Again...
          Thank you very much.
          Ricardo

          Comment

          Working...