I've found that this does a very inneficient job of storing the characters. I think it's creating some temp variable every time it does a concatination which becomes very expensive as HeadData becomes large. Any suggestions? Thanks!

-Dan

Sent via Deja.com http://www.*-*-*.com/ Before you buy.

Wed, 18 Jun 1902 08:00:00 GMT

Paul Marshal#2 / 8

Efficient string concatination

?I'm trying to take an array of Bytes, convert each byte into a ?character and store it all in a String. What I've been using is: ? ?For LongCount = 0 To LongByteCount - 1 ? HeadData = HeadData & Chr(ByteArray(LongCount)) ?Next ? ?I've found that this does a very inneficient job of storing the ?characters. I think it's creating some temp variable every time it does ?a concatination which becomes very expensive as HeadData becomes large. ?Any suggestions? Thanks!

Hi Dan,

Does this do what you want?

HeadData = StrConv(ByteArray, vbUnicode)

-- Paul Marshall

Wed, 18 Jun 1902 08:00:00 GMT

ADP#3 / 8

Efficient string concatination

Since you're starting w/ a byte array, the prior respondent's approach is best.

In general, however, VB does do a lot of BSTR allocation when concatenating strings, and that can lead to performance issues. In normal cases performance is affected by 2 factors: length of concatenated strings, and order of concatenation.

Turns out that the OLE subsystem maintains a string cache of 60K or so, so concatenations that fit in this size are quick enough. Longer strings are heap-allocated and take considerably longer to effect.

Also related to the above, the performance of a statement such as:

sLongString = sLongString & " " & vbCrlf

can be significantly increased by specifying the concatenation order so that small strings are concatenated first. Like so:

sLongString = sLongString & (" " & vbcrlf)

Finally, the quickest way to concatenate strings in VB6 is to use the Join() function. Of course, since Join() takes an array arg, we have to deal with dimensioning an array of adequate size in the first place. This can be done using repeated ReDim's (a bad idea), or Dim-ing a large array then messing with its SAFEARRAY info so Join() sees only the elements you want it to.

The above is from Matt Curland's 'Advanced VB 6' from Addison Wesley. Please refer to it for details.

> In general, however, VB does do a lot of BSTR allocation when concatenating > strings, and that can lead to performance issues. In normal cases > performance is affected by 2 factors: length of concatenated strings, and > order of concatenation.

> Turns out that the OLE subsystem maintains a string cache of 60K or so, so > concatenations that fit in this size are quick enough. Longer strings are > heap-allocated and take considerably longer to effect.

> Also related to the above, the performance of a statement such as:

> sLongString = sLongString & " " & vbCrlf

> can be significantly increased by specifying the concatenation order so that > small strings are concatenated first. Like so:

> sLongString = sLongString & (" " & vbcrlf)

> Finally, the quickest way to concatenate strings in VB6 is to use the Join() > function. Of course, since Join() takes an array arg, we have to deal with > dimensioning an array of adequate size in the first place. This can be done > using repeated ReDim's (a bad idea), or Dim-ing a large array then messing > with its SAFEARRAY info so Join() sees only the elements you want it to.

> The above is from Matt Curland's 'Advanced VB 6' from Addison Wesley. > Please refer to it for details.

> --A

Wed, 18 Jun 1902 08:00:00 GMT

J Fren#5 / 8

Efficient string concatination

Surely this will push ANSI bytes into an ANSI copy of a UNICODE string which VB will then re-convert into UNICODE

In general StrConv looks better for this type of operation.

If concatenating true strings (not byte array to string) and speed is critical then the trick is to pre-format the final string, and then insert the smaller strings using Mid$

>> In general, however, VB does do a lot of BSTR allocation when >concatenating >> strings, and that can lead to performance issues. In normal cases >> performance is affected by 2 factors: length of concatenated strings, and >> order of concatenation.

>> Turns out that the OLE subsystem maintains a string cache of 60K or so, so >> concatenations that fit in this size are quick enough. Longer strings are >> heap-allocated and take considerably longer to effect.

>> Also related to the above, the performance of a statement such as:

>> sLongString = sLongString & " " & vbCrlf

>> can be significantly increased by specifying the concatenation order so >that >> small strings are concatenated first. Like so:

>> sLongString = sLongString & (" " & vbcrlf)

>> Finally, the quickest way to concatenate strings in VB6 is to use the >Join() >> function. Of course, since Join() takes an array arg, we have to deal >with >> dimensioning an array of adequate size in the first place. This can be >done >> using repeated ReDim's (a bad idea), or Dim-ing a large array then messing >> with its SAFEARRAY info so Join() sees only the elements you want it to.

>> The above is from Matt Curland's 'Advanced VB 6' from Addison Wesley. >> Please refer to it for details.

>> --A

Wed, 18 Jun 1902 08:00:00 GMT

Ian#6 / 8

Efficient string concatination

I as understand it StrConv performs the same operation as RTLMoveMemory, but there's one situation where StrConv wins hands down and that is when the array is in a variant variable, with RTLMoveMemory you get rubbish back.

>I as understand it StrConv performs the same operation as RTLMoveMemory, but >there's one situation where StrConv wins hands down and that is when the >array is in a variant variable, with RTLMoveMemory you get rubbish back.

> >> In general, however, VB does do a lot of BSTR allocation when > >concatenating > >> strings, and that can lead to performance issues. In normal cases > >> performance is affected by 2 factors: length of concatenated strings, and > >> order of concatenation.

> >> Turns out that the OLE subsystem maintains a string cache of 60K or so, so > >> concatenations that fit in this size are quick enough. Longer strings are > >> heap-allocated and take considerably longer to effect.

> >> Also related to the above, the performance of a statement such as:

> >> sLongString = sLongString & " " & vbCrlf

> >> can be significantly increased by specifying the concatenation order so > >that > >> small strings are concatenated first. Like so:

> >> sLongString = sLongString & (" " & vbcrlf)

> >> Finally, the quickest way to concatenate strings in VB6 is to use the > >Join() > >> function. Of course, since Join() takes an array arg, we have to deal > >with > >> dimensioning an array of adequate size in the first place. This can be > >done > >> using repeated ReDim's (a bad idea), or Dim-ing a large array then messing > >> with its SAFEARRAY info so Join() sees only the elements you want it to.

> >> The above is from Matt Curland's 'Advanced VB 6' from Addison Wesley. > >> Please refer to it for details.