473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

circular buffer in C++

Hi there,
I have to write an optimized circular buffer to log events in C++. The
elements are of type std::string. This should run under Linux on an ARM
embedded system. I can dedicate to this circular log a preallocated
block of fixed size and work in there.
Can anybody indicate me an example or technique to do this ?

Thanks

Marco

Oct 20 '06 #1
2 7733
marco.fur...@syac.com wrote:
Hi there,
I have to write an optimized circular buffer to log events in C++. The
elements are of type std::string. This should run under Linux on an ARM
embedded system. I can dedicate to this circular log a preallocated
block of fixed size and work in there.
Can anybody indicate me an example or technique to do this ?
Check out the circular buffer that will soon be part of Boost. The docs
can be found (in a slightly dated form) here:

http://myweb.tiscali.co.uk/gaspar/circular_buffer.html

and the code can be found in the Boost sandbox:

http://boost-sandbox.cvs.sourceforge...sandbox/boost/

Look at circular_buffer.hpp and the circular_buffer subdir.

Cheers! --M

Oct 20 '06 #2
mlimber wrote:
marco.fur...@syac.com wrote:
>>Hi there,
I have to write an optimized circular buffer to log events in C++. The
elements are of type std::string. This should run under Linux on an ARM
embedded system. I can dedicate to this circular log a preallocated
block of fixed size and work in there.
Can anybody indicate me an example or technique to do this ?


Check out the circular buffer that will soon be part of Boost. The docs
can be found (in a slightly dated form) here:

http://myweb.tiscali.co.uk/gaspar/circular_buffer.html

and the code can be found in the Boost sandbox:

http://boost-sandbox.cvs.sourceforge...sandbox/boost/

Look at circular_buffer.hpp and the circular_buffer subdir.
I don't know if it's too clear here, but a circular buffer is actually
two logical queues. So a pop from a circular buffer is a pop from the
full queue and a simultaneous push into the empty queue. In multi-threading
that means you have to push and pop by value. In particular, if you pop
by reference, the value you are referencing can be modified by another
thread so you want to avoid that. The OP wants to use strings and wants
to avoid buffer allocation and deallocation so I imagine that means
deep copying of strings. The internal refcounted string implementations
that don't deep copy would probably involve too much allocation/deallocation
overhead.

The example here probably wouldn't work for the OP's purpose if they're
multi-threading.
http://myweb.tiscali.co.uk/gaspar/ci...#boundedbuffer
--
Joe Seigh

When you get lemons, you make lemonade.
When you get hardware, you make software.
Oct 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
2
by: Bob Jenkins | last post by:
I have this cute data structure that I just found a second opportunity to use. I googled for references to it, but came up empty. I probably just don't know its name. The algorithm on this...
2
by: William Stacey | last post by:
Working with implementing a circular buffer for a producer/consumer deal. Have not done one in a while. The following seems to work. However, I remember and have seen other implementation that...
23
by: Rogers | last post by:
I want to compare strings of numbers that have a circular boundary condition. This means that the string is arranged in a loop without an end-of-string. The comparaison of two strings now...
11
by: Kenneth Lantrip | last post by:
Anyone got any ideas as to how this process could be improved for speed? this is what I have... Dim j, q As Integer Dim x(16), y(16) As Byte x.CopyTo(y, 0) ' shift left circular 24 bits
10
by: avsrk | last post by:
Hi Folks I want to create a circular queue for high speed data acquistion on QNX with GNU C++ . Does any one know of efficient ways either Using STL or in any other way . I am thing of ...
7
by: toton | last post by:
Hi, I want a circular buffer or queue like container (queue with array implementation). Moreover I want random access over the elements. And addition at tail and remove from head need to be low...
5
by: shofu_au | last post by:
Dear readers, Before poorly reinventing the wheel I thought I would ask if a class already exists. I need to use a circular byte buffer that is thread safe. I cannot use MSMQ, my regular...
12
by: Sven | last post by:
Can someone point out source code for a safe circular buffer receiver transmitter? It's for sending and receiving bytes via RS232. Thanks in advance.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.