By Brian Yule (byule at PembrokeTechnology.com)
Download the project (20 kb)
It's long been said that VB is not good at custom data type handling.
This code provides a framework for building your own data types in VB6.
This project cotains the concept of using memory to hold data and to
wrap the data held as a data type. In addition, the code comes
with your own implementation of
Integer, Long, Byte, ByteArray, String and StringBuilder (similar to the
idea used for StringBuilder class in .NET).
Because these new data types are objects you can add whatever methods and property you want.
For instance, you can replicate whatever .NET offers. In addition, it is
possible to create Data Types that are not even available in VB, like an
Unsigned Int or whatever else.
So just for fun, I compared concatenation performance of the standard VB String
Data Type versus the clsString custom string data type and the StringBuilder. Amazingly enough, the clsString class
on average 50 to 80 times faster (that's x * 80) than the regular string class.
The StringBuilder class gets progressively faster as the string size gets bigger. For instance,
when the string is concatenated 5000 times, it is 75 times faster than the String type. When
the string is concatenated 50,000 times, the StringBuilder is nearly 1200 times faster (yep, that's
x * 1200). In fact, the performance of the StringBuilder class is nearly identical to that of
the StringBuilder class in .NET, which is considered the fastest thing since the Road Runner cartoon.
| Concatenations (number of times) |
5000 |
10000 |
25000 |
50000 |
| Standard VB String Data Type (seconds) |
1.171875 |
10.26563 |
85.6875 |
355.4375 |
| Custom String Data Type (seconds) |
0.015625 |
0.125 |
1.4375 |
6.078125 |
| StringBuilder class (seconds) |
0.015625 |
0.046875 |
0.109375 |
0.296875 |
|
|
|
|
|
| clsString Times faster |
75 |
82 |
59 |
58 |
| StringBuilder Times faster |
75 |
219 |
783 |
1197 |
Download the project (20 kb)