Groups | Blog | Home
all groups > inetserver asp components > november 2003 >

inetserver asp components : Concatenation help


David P. Jessup
11/24/2003 8:22:54 AM
Good day folks,

I finally broke down and wrote my first DLL to "secure" my asp code.

One of the classes I wrote in the object contains many string lines.

So I'm currently writing the code like this:

Function myClass(variables) as string

myString = myString & "......"
myString = myString & "......"
etc

myClass = myString
end function

I'm just wondering if there is a better way to handle this.

--
Thanks from this ASP Newbie

Cowboy (Gregory A. Beamer)
11/24/2003 8:42:47 AM
It depends. In some instances, you are better writing directly to the
stream:

Response.Write AnotherString
Response.Flush

It depends on the amount of information you are concatenating. With
components, you will have to get the ASP context, which is most easily
pulled from COM+ (IIS runs under COM+ in Windows 2000 - NOTE: MTS is
basically COM+ (minus some features) for Windows NT 4.0).

If each string line is short, you are better concating the string. In
general, a Response directly from the component is less expensive than
outputting the string from the class and writing from ASP. With small
strings, this is not necessarily true.

One more note: Do not necessarily default to performance. Understandable
code is far more valuable than code that saves a few milliseconds (at least
in most applications), so consider maintainability in your equation.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
[quoted text, click to view]

David P. Jessup
11/24/2003 9:15:08 AM
Thanks for the response Gregory. I guess I could have stated a few more
details in my original post.

This particular class object is actually iterating through an array from a
DB and building a table, with paging too.

I guess I'll put some timings in and check against my original
response.write in the original ASP before I moved it to my DLL.

If the class is only writing a table with only one record I'm dealing with
about 32 string lines that need to have concatenation done to them. But my
experience with the in-house DB is that my users pull hundreds(sometimes
thousands when users don't know how to delimit their SQL queries) of records
at once and page through them.

Again, thanks for replying so quickly, have a great day.


--
Thanks from this ASP Newbie
"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
message news:uAPxTopsDHA.1756@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

Pat [MSFT]
11/24/2003 3:32:02 PM
String Concatenation becomes exponentially more expensive as the string size
increases (apprx linear to 256k, exponential after that). There are a
number of reasons for this (how OLEAUT32 caches BSTRs, Heap design), so for
small strings, what you are describing should be fine. If you are doing a
lot of strings, the string size is large, or if this is a high stress part
of code, then you should use the mid() function within a loop to implement
your concatenation. There are a number of string 'classes' out there that
do this. You can refer to Hardcore Visual Basic for a good example.

See http://support.microsoft.com/default.aspx?scid=kb;en-us;170964.


Pat



[quoted text, click to view]

Chris Barber
11/24/2003 11:41:59 PM
See the following thread in microsoft.public.xml about benchmarking string
builder classes - there's even a couple of VB projects to download.

Basically, *anything* is better than concatenation for anything beyond a few
lines of text.

http://tinyurl.com/wedq

Cheers,

Chris.


[quoted text, click to view]
Thanks for the response Gregory. I guess I could have stated a few more
details in my original post.

This particular class object is actually iterating through an array from a
DB and building a table, with paging too.

I guess I'll put some timings in and check against my original
response.write in the original ASP before I moved it to my DLL.

If the class is only writing a table with only one record I'm dealing with
about 32 string lines that need to have concatenation done to them. But my
experience with the in-house DB is that my users pull hundreds(sometimes
thousands when users don't know how to delimit their SQL queries) of records
at once and page through them.

Again, thanks for replying so quickly, have a great day.


--
Thanks from this ASP Newbie
"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
message news:uAPxTopsDHA.1756@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]


Cowboy (Gregory A. Beamer)
11/25/2003 10:10:48 AM
With small amounts of data (< 256k or so), you do not have a major problem.
Beyond that, you end up having to chunk out data (ie, Response.Write/Flush
prior to hitting the 256k mark). This is most easily done by having the
Response object write from the component. To set up the Response object, you
will have to get Context, which is most easily pulled by making the
component a COM+ component. This adds some benefits, but also adds a bit of
weight itself. The weight is more than outputting a small amount of data,
but less that concatenating huge strings.

If this is not an option, moving to .NET is a good option, as the
StringBuilder class gives you the ability to work with rather large chunks
of text. Of course, you would more likely change methodologies and bind the
data rather than chunk it out.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
[quoted text, click to view]

AddThis Social Bookmark Button