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

  • Home
  • SEARCH
  • 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 8625193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:43:19+00:00 2026-06-12T07:43:19+00:00

In our application we have a class that produces characters, and another that consumes

  • 0

In our application we have a class that produces characters, and another that consumes them. The current implementation dynamically allocates characters as they are produced (using new) and delete them (with delete) as they are consumed. This is all terribly slow, and I am looking at ways to replace that implementation to improve its performance.

The semantic I need is that of the standard class queue: push at the front, pop at the back. The default implementation uses a deque IIRC. deque is typically implemented using “blocks” or “chunks” of memory, so I expect far less calls to the OS memory allocator, and a significant speed-up, with little additional memory usage.

However, since the data queued is characters (possibly wide characters), an alternative would be to use the standard input/output stream class, namely the character stream stringstream. AFAIK, their behaviour is queue-like too.

Is there a better choice a priori? Would both classes have similar allocation patterns? I can try and measure performance of both, but perhaps it doesn’t really matter and either would be good enough. In that case, which would be easiest/safest to use?

A secondary matter is concurrency between the producer and the consumer. I can restrict access to be sequential (on the same thread), but a thread-safe implementation is likely to be beneficial performance-wise with current multi-core hardware.

Thanks for your wisdom before I dive in and start coding.

  • 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-06-12T07:43:20+00:00Added an answer on June 12, 2026 at 7:43 am

    std::stringstream isn’t a queue, since reading characters doesn’t consume them. You can simply seekg(0) and read the same characeters all over again. Thus, the more you write, the more memory you will consume.

    Stick with std::queue. The default choice of std::deque as the underlying implementation is almost certainly the right one.

    Regarding concurrency, it is categorically unsafe to write to std::queue while any other thread is reading or writing to it. If you want an efficient blocking queue implementation, you’ll have to write or borrow one specifically built for the purpose.

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

Sidebar

Related Questions

So we have our J2EE application using Log4j like this public class CustomerController {
In our application we have a little query that looks like this: var selectedAgents
We have two tables in our application that both have a ShowOrder column. We
Our application is a Java-GWT application that uses Guice-Persist and Guice-Servlet extensively. We have
I have a class that implements a plugin for an existing application. I also
In our application I have a routine that manually iterates over the properties of
We have a class that holds configuration information for the application. It used to
In our application, we have a number of Windows Services (more than 30) that
In our web project, we have a custom Database Connection class that creates the
In our application we have a class called GlobalPage.cs this page inherits from Page

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.