Erik Porter's Blog

Life and Development at Microsoft and Other Technology Discussions

News

    StringBuilder and String Concatination

    Someone over at We're Here (big Flash community site) was asking why String Concatination is so slow in .NET.  He found the StringBuilder Class so I thought I'd take the opportunity to explain the two and how they work, etc.

    This topic has been talked about a lot, but I thought I'd just point this ramble out in case someone might learn something they didn't know, maybe teach me something I don't know.

    Comments

    Daniel Jin said:

    I couple mistakes I'd like to point out in that ramble.

    about string interning. only string literals are interned. dynamically created strings are never interned. you can call String.Intern(), to add a non-interned string to the intern pool if one with the same value is not already in the pool, or return the one in the pool otherwise.

    string interning has nothing to do with connection pooling. yes, connection pooling is by connection string, but if you have two different instance of connection strings that have the exact same value but actually are references to different strings, it will be the same connection pool. different pools will result if the values (not references) are not identical, say if one has an extra space than the other.
    # June 8, 2004 6:31 PM

    HumanCompiler said:

    Thanks for the corrections about Intern...I didn't really know what it meant and more just meant to say "internal".

    For some reason I was confused and thought that two strings with the same value would reference the same internal string, which is why I made the assumption about connection strings, but what you said makes total sense about all that matters is that the values match, not reference.

    Thanks for the corrections, Daniel!
    # June 8, 2004 6:55 PM

    michael said:

    I actually ran a test a while back:

    http://www.melloblog.com/Feedback.aspx?BlogID=47
    # June 8, 2004 11:48 PM

    HumanCompiler said:

    cool, thanks for the link! :)
    # June 9, 2004 12:01 AM