By Michael Balloni
StrCat.Catter - An Efficient String Concatenation Component, Part 2
In Part 1 we looked at the motivation for
StrCat.Catter. In this part we'll look at the implementation and some
For those who know IDL - or can fake it -
Catter's interface is as follows:
As you can see, this is general-purpose string assembly engine. At first there was
Resolve. Then I found that I needed
Surround. I mostly use
Dump instead of
Resolve because it frees resources sooner.
Reset are included for completeness.
I like to use this component for concatenation of SQL query strings, both in VB and in ASP scripts. SQL Server devours big batches of SQL much better than lots of little requests. Since
Catter is so efficient, great gains can be had when the
size of the strings and the number of concatenations grows. As an example, I use this
component to manufacture SQL that marks all of a set of database-modelled files and
folders and their children folders and files as public or private. If there are just a
few files and folders, you can get away with VB string concatenation. Throw in a few
thousand files and deeply nested folders, and you need the improved performance of
Catter outperforms standard VB string concatenation after several dozen concatenations. Here's The results can be seen below. If you're interested in the code tests I used, check out the VB test code used. Note that is employs the use of a free component, ASP Profiler. To run this code you will need to download and install the component.
|Concatenations||Length of String||VBScript Concatenation|
You can see that it takes about three times longer to get
Catter up to speed
for a single concatenation, and even after a few dozen
Catter lags behind.
But once VB starts to slow down, it does so disastrously - quadratically, in fact - and
Catter keeps its cool, staying almost linear in terms of time versus
concatenations. I'd hate to be the person waiting 25 seconds for VB to concatenate some strings!
Catter is an STL vector of STL wstrings.
calls on the reserve methods of both the vector and wstring classes. The implementations
of these classes are designed so that their execution time stays linear under these
circumstances. They accomplish this by doubling their allocated memory when they need
to grow, thereby avoiding making too many allocations and fragmenting the heap.
When you need to concatenate more than a few dozen strings, consider using
Catter's optimized C++ implementation can
prevent your site from CPU saturation when folks start asking more of it than VB can
StrCat.Cattersource code and DLL in ZIP format
StrCat.Catter and many other COM components power
Streamload.com, a digital entertainment
delivery site offering unlimited free online storage - no catch: upload all your files
from your computer - and a bevy of media-savvy services including compression (ZIP-ing),
quality conversion (BMP -> JPEG, watermarking), de-digitization (CD burning, disk magnetization),
and a full micro-transaction digital commerce engine (create memberships, sell files to
subscribers and the world). This is not another drive site: This is your digital entertainment,