I was recently instructed to implement a buffer that will be used as temporary storage for the logging class. The journal class itself is a singleton, and the listener-observer pattern is used. You can expect thousands of posts to be recorded in this class.
Now the problem is here:
We have a trace tracking option that is used for degradation purposes. When this option is enabled, the number of messages / seconds increases exponentially. The release code tracking protocol is disabled, however, a buffer that can store a fixed number of messages, for example. 10000 is flushed to the IF log , an error occurs so that developers can determine the root of the problem.
If the buffer is full, the oldest message is deleted 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
{
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 use constant delete / insert time. (do not ask for the deprivation of emptiness, not for my decision).
, , ? , , /, 0. , - 1, 0, , .
, STL ?
, . , .