Why is concatenation slow??

Results 1 to 3 of 3

Thread: Why is concatenation slow??

  1. #1
    Join Date
    Dec 1969

    Default Why is concatenation slow??

    In many places I&#039;ve seen it stated that concatenation with & is slow in VB, but I don&#039;t think I&#039;ve heard a good explanation of why.<BR><BR>I read Bill&#039;s excellent articles about variants, values, and arrays and learned that a variant refernce to a string stores the address of the memory location that holds the string. I&#039;m curious as to what happens when you concatenate and why it&#039;s particularly slow. <BR><BR>If anyone has an answer or can point me to an article I&#039;d appreciate it.

  2. #2
    tal farlow Guest

    Default as far as i can understand...

    ...the problem isn&#039;t really that it&#039;s all that slow, but that it hogs up resources<BR><BR>this is how i&#039;ve been told it works...<BR>if we have a string, str, and want to add some more characters to it, we would probably do this:<BR><BR>str & "this " & "is " & "fun!"<BR><BR>what happens there is that a copy is made of str and held in memory and then "this " is appended to it, then a copy is made of that new string and "is " is appended to it, etc. so you can imagine how much resources could be taken up with large concats on a heavily trafficked site<BR><BR>that&#039;s how i&#039;ve been told it works ate least - if my explanation is incorrect, i&#039;d like someone to correct me please

  3. #3
    Join Date
    Dec 1969

    Default Makes sense... Anyone else??

    That would make sense as to why resources are getting hogged. The simple concatenation would cause 4 strings to be held in memory.<BR><BR>str & "this " & "is " & "fun!"<BR><BR>I&#039;ve definately seen articles where people run tests that say it runs 100 times slower (or whatever) when they concatenate vs some other method. And supposedly this amount of time increases exponentially as the concatonations increase. Seems like if it was just memory then it would be fast up to the point where memory became an issue and then bog. Plus I guess the time to actually make a copy of the ever increasing string would increase

Posting Permissions

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