Boost logo

Boost Users :

Subject: [Boost-users] boost::circular buffer- avoid memory allocation
From: Lloyd (lloyd_at_[hidden])
Date: 2010-05-24 01:34:24


Hello,

We are using circular buffer. The producer generates the data (a 1024byte char buffer) and the consumer reads it from circular buffer. In normal case the producer allocates the memory for each item. we believe this is very inefficient, so that we are going for circular buffer. How can we make the circualr buffer to allocate the memory in advace and make it possible for the producer and consumer to share it.

For example if the buffer is of 10 nodes, the totoal memory allocated by circular buffer would be 10*1024, isn't it?

How can the producer get the pointer to the next free node available in the circular buffer? (so as to avoid memory allocation by the producer)
How can the consumer get pointer to the data to be read next?

The sample available in boost::circular buffer describes it with a simple integer based example. I think this kind of problem is not addressed in it. Some hint will be very useful.

Thanks,
 Lloyd

______________________________________
Scanned and protected by Email scanner



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net