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