VBspeed / String / AllocString
VBspeed © 2000-10, updated: 27-Oct-2001
AllocString


Function AllocString
Allocates a new string of a specified size. Contents can remain undefined.

Normally you would allocate string space using the String$ or the Space$ function (the latter is faster). However, on top of merely allocating space, both functions fill up all the space with a specified bit sequence. This takes time. If you do not need this favor, there should be faster ways to allocate string space...
Code
AllocString01
Public Function AllocString01(ByVal lSize As Long) As String
  AllocString01 = Space$(lSize)
End Function
  
AllocString02
Public Function AllocString02(ByVal lSize As Long) As String
  AllocString02 = String$(lSize, 32)
End Function
  
AllocString03
Public Function AllocString03(ByVal lSize As Long) As String
  AllocString03 = String$(lSize, " ")
End Function
  
AllocString04
Public Function AllocString04(ByVal lSize As Long) As String
' by Jory, jory@joryanick.com, 20011023
  RtlMoveMemory ByVal VarPtr(AllocString04), _
    SysAllocStringByteLen(0&, lSize + lSize), 4&
End Function
  
AllocString05
Public Function AllocString05(ByVal lSize As Long) As String
' by Donald, donald@xbeat.net, 20011027 (TLB by Guido)
  AllocString05 = bstrapi.SysAllocStringLen(vbNullString, lSize)
End Function
  
AllocString06
Public Function AllocString06(ByVal lSize As Long) As String
' by Donald, donald@xbeat.net, 20011027 (TLB by Egbert)
  AllocString06 = StringHelpers.SysAllocStringLen(ByVal 0&, lSize)
End Function
  
[05.inline]
sRet = bstrapi.SysAllocStringLen(vbNullString, lSize)
  
[06.inline]
sRet = StringHelpers.SysAllocStringLen(ByVal 0&, lSize)
  
Dope
API Private Declare Sub RtlMoveMemory Lib "kernel32" (dst As Any, src As Any, ByVal nBytes&)
Private Declare Function SysAllocStringByteLen& Lib "oleaut32" (ByVal olestr&, ByVal BLen&)
TLB TLB StringHelpers (3KB, VB5-compatible. by Egbert Nierop)
TLB BStrAPI (2KB, VB5-compatible, by G.Beckmann)
Calls
1sRet = AllocString(1)
2sRet = AllocString(100)
3sRet = AllocString(10000)
4sRet = AllocString(1000000)
Charts
 VB5 Charts
CodeAuthorDopingNotes
AllocString01 (native)  
AllocString02 (native)  
AllocString03 (native)  
AllocString04 JoryAPI 
AllocString05 DonaldTLB 
AllocString06 DonaldTLB 
[05.inline] DonaldTLB 
[06.inline] DonaldTLB 
Call 1
51.441.122µs
72.311.801µs
83.032.368µs
61.721.346µs
41.351.054µs
31.230.964µs
21.120.875µs
11.000.781µs
Call 2
62.001.522µs
72.782.119µs
83.532.689µs
51.741.330µs
41.371.042µs
31.270.967µs
21.140.866µs
11.000.762µs
Call 3
682.4867.191µs
783.5268.039µs
884.4968.826µs
51.681.372µs
41.371.119µs
31.220.995µs
21.140.929µs
11.000.815µs
Call 4
651.2116,313µs
851.3016,341µs
751.2816,332µs
51.02325µs
41.00320µs
31.00319µs
21.00319µs
11.00319µs
 VB6 Charts
CodeAuthorDopingNotes
AllocString01 (native)  
AllocString02 (native)  
AllocString03 (native)  
AllocString04 JoryAPI 
AllocString05 DonaldTLB 
AllocString06 DonaldTLB 
[05.inline] DonaldTLB 
[06.inline] DonaldTLB 
Call 1
41.361.177µs
72.081.793µs
82.912.511µs
61.761.519µs
51.371.187µs
31.231.064µs
21.140.983µs
11.000.863µs
Call 2
61.871.624µs
72.622.275µs
83.593.117µs
51.741.507µs
31.251.081µs
41.251.089µs
21.181.020µs
11.000.868µs
Call 3
672.8167.575µs
773.9268.604µs
874.7769.387µs
51.711.582µs
31.181.093µs
21.091.007µs
41.251.163µs
11.000.928µs
Call 4
650.9716,275µs
851.0316,296µs
751.0116,289µs
51.02327µs
41.01321µs
21.00320µs
31.00320µs
11.00319µs
Conclusions
Things do get interesting somewhere between 100 and 10000 chars, don't they? But remember: you cannot predict what's inside those fast-allocated strings.
Got comments? How to read all those numbers

top




VBspeed © 2000-10 by Donald Lessau