First, the queue core class can use a reusable pool, but this is for internal management of it's own pointers. The queue is passed an object to post into it that is derived from "Object", which are reference counted. Hence, existing on the queue is actually a reference count instance of a reference counted object. However, if you want a resuable pool of buffer objects, you would construct an object for your buffer that is itself derived from ReusableObject (which is derived from Object), and this is what you would then pass into the queue.
Hence maybe you would use something like: class MyObject : public ReusableObject { public: char data[100]; }; static mempager datapool; // we have a pool with a maximum allocation size of 100 objects... static paged_reuse<MyObject> bufpool(&datapool, 100); // and a fixed size stream buffer of referenced objects... static queueof<MyObject> mycache(&datapool, 10); // we have a cache for these 100 objects... to post: // timeout to try MyObject *x = bufpool.get(100); // on error getting a new pool object... if(!x) ... we could allocate from datapool, throw, whatever... // we may also need to add x->retain(), it's been awhile.... // make sure it survives cache... String::set(x->data, 100, "something"); // timeout possible... if(!mycache.post(x, 100)) ... failed to post ... to get an object from the queue: // with a timeout... MyObject *x = mycache.lifo(100); if(!x) ... we didn't get anything before timer expired... printf("data %s\n", x->data); // release object back to reuse pool... bufpool::release(x) What is confusing is that paged_reuse and the related PagerReuse is in vector.h. It probably should be in thread.h :). And yes, this particular construction is unique to ucommon, and particularly it's preference for reference counted objects, so I am sure the construction of this is not at all obvious, but once it is seen it makes complete sense. It is a reason we need more examples... Both paged_reuse and queueof use conditionals to protect boundaries, and with millisecond timeouts to give time limits waiting for resources (such as an object released from another thread when empty, or for another thread to pull data if the cache is full). On 06/03/2010 08:38 PM, Leon Pollak wrote: > Thank you David. > > I shall be really glad if you will be able to give me the list of classes to > be used for the following simple task: > Two threads A and B. > A receives data from somewhere into buffers (of the same size) polled from > buffer pool (which classes?). > Then A sends these buffers to B (which classes). > B receives buffers, process them and returns to the pool. > > Just, please, name the classes, i will try to understand how to use them... > > Thanks again. > > On Thursday June 3 2010, David Sugar wrote: >> The queue class was written because there are some older Bayonne drivers >> that would likely make use of it when the rest of Bayonne is ported to >> ucommon, and it is also based on some stuff also used in the original >> Common C++. However, those drivers (in particular, Dialogic and Pika, >> which used an event queue to buffer realtime Dialogic events to Bayonne >> ones) had not been ported to the newer Bayonne codebase as yet. So it >> is quite possible there is nobody currently using the class. I think if >> this is true we should at least make sure there is some unit test code >> coverage for queue. >> >> On 06/03/2010 10:29 AM, Leon Pollak wrote: >>> Hello. >>> >>> I am a newbie here - sorry for stupid questions (but I am definitely not >>> a newbie in RT programming - 16 years with RTEMS, pSOS and similar). I >>> also hope that this is the correct place for such questions. >>> >>> I am trying to understand uCommon queues with the help of doxygen >>> documentation and examples (bayonne, ccaudio, ccscript, sipswitch) source >>> code. >>> >>> Unfortunately, I was not able to find ANY usage of the ucc::queue in >>> these projects! >>> >>> Does this mean that I do not know to search or queues are not used for >>> some reason? >>> >>> A lot of thanks ahead. > >
<<attachment: dyfet.vcf>>
_______________________________________________ Bug-commoncpp mailing list Bug-commoncpp@gnu.org http://lists.gnu.org/mailman/listinfo/bug-commoncpp