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 6796709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:31:14+00:00 2026-05-26T18:31:14+00:00

I was recently tasked on implementing a buffer which will be used as a

  • 0

I was recently tasked on implementing a buffer which will be used as a temporary storage by a logging class. The logging class itself is a singleton and the observer listener pattern is used. You can expect thousands of messages to be logged with this class.

Now the problem lies here :

We have a trace logging option which is used for deguging purposes. When this option is on, the count of messages/second is increased exponentially. In the release code trace logging is disabled, however a buffer which can store a fixed number of messages e.g. 10000 is dumped into the log IF an error occurs, so that the developers can identify the root of the problem.

If the buffer is full the oldest message is removed to free space for the newest message.

void Log::storeToBuffer(const LogType_E & type_in, const LogDomain_E & domain_in,const int & id_in, const char * msg_in)
{
    if(this->myEnableTraceBuffer)
    {
        if(static_cast<std::list<Message> * >(this->myRingBuffer)->size() < this->myRingBufferMaxSize)
        {
            static_cast<std::list<Message> * >(this->myRingBuffer)->push_back(Message(type_in, domain_in, id_in, msg_in));
        }
        else
        {
            //buffer full so remove oldest element and add new
            if(static_cast<std::list<Message> * >(this->myRingBuffer)->size() > 0) static_cast<std::list<Message> * >(this->myRingBuffer)->pop_front();
            static_cast<std::list<Message> * >(this->myRingBuffer)->push_back(Message(type_in, domain_in, id_in, msg_in));
        }
    }
}

I implemented this with std::list , very simply using push_back/pop_front to exploit the constant delete/insert execution time. (don’t ask for the void casting, not my decision).

But since the buffer size is fixed, and not likely to be changed during the lifetime of an object, maybe vector with explicit index manipulation is more suitable? For example there can be two indeces , start/current starting both at position 0. When the vector is full and we add something start moves to position 1 and and current to position 0, thus when printing the result we have the right order.

Maybe another STL container is more suitable for this kind of thing?

Thank your for your patience to read this long wall of text. I am here to answer any questions.

  • 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-26T18:31:14+00:00Added an answer on May 26, 2026 at 6:31 pm

    Ever heard of std::deque? 🙂
    It allows amortized constant time random access and constant time push/pop operations on both sides. As such, it can be easily used as a FIFO queue.

    That said, since it can be used as such so easily, there is a container adaptor std::queue, though it doesn’t offer random access and an iterator interface.

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

Sidebar

Related Questions

I've recently been tasked with adding logging statements to every method call in a
I was recently tasked with coming up with an offsite backup strategy. We have
I was recently tasked with debugging a strange problem within an e-commerce application. After
Recently I was tasked with writing up formal procedures for a team based development
I've been tasked with the the maintenance of a nonprofit website that recently fell
I think I may be trying something that isn't possible. I was recently tasked
I've recently been tasked with improving a records database that consists of the following:
Recently a new co-op was hired at our company and has been tasked to
I have recently been tasked with upgrading an application from .net 1.1 to 3.5
We use MOSS 2007 (SharePoint) for our intranet. Recently we were tasked with supporting

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.