Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 961131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:17:36+00:00 2026-05-16T01:17:36+00:00

I receive around 5 messages per second. Each of them has a string, which

  • 0

I receive around 5 messages per second. Each of them has a string, which I concatenate to a master string that contains all the received messages

    string _masterText = "";
    public void AddNewMessage(string text)  // this is going to be call at least 5 times/second
    {
        _masterText += text;    
    }

Is this the appropiated way to do it? or should I use instead StringBuilder, like:

    StringBuilder _masterText = new StringBuilder();
    public void AddNewMessage(string text) // this is going to be call at least 5 times/second
    {
         _masterText.Append(text);  
    }

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:17:37+00:00Added an answer on May 16, 2026 at 1:17 am

    StringBuilder is generally considered the better option, but in this case I’d use neither.

    Even with StringBuilder, at that rate the underlying character buffer will soon itself be large enough to get stuck on the Large Object Heap. This will cause problems for the health of an application that needs to stay running for a while.

    Instead, I’d use a System.Collections.Generic.List<string> and just call it’s .Add() method for each new message. Depending on what you do with these messages you may also find another collection type is more appropriate (perhaps a Queue<string>), but this is the direction you should go. By using a collection, the memory used by each individual string will not count towards the size of the collection object. Instead, each string will only add a few bytes for the reference. This will take a lot longer to run into problems with compacting the Large Object Heap.

    If you still have problems after switching to a collection, you can use a stream, and write the strings to disk. This way, you never have more than one string in RAM at a time. Now, the only way you have problems is if individual strings are 85000 bytes or larger.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I receive a daily XML file that contains thousands of records, each being a
From what i've read around about winsock, recv has a tendency to not receive
I receive a string from a database query, then I remove all HTML tags,
I receive an empty value for NSMutableArray and already checked that was filled properly.
I'm using Boost asio to send and receive framed TCP messages. Does anyone know
I currently need to make the silverlight 4 in-browser app that can receive push
Passing messages around with actors is great. But I would like to have even
We have a MSMQ Queue setup that receives messages and is processed by an
I've looked around and I haven't found anything that fits my needs. I wish
I am using a queue service that only takes messages as byte so I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.