bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: HowTo for queues - open issues resolved in 3.0.1


From: David Sugar
Subject: Re: HowTo for queues - open issues resolved in 3.0.1
Date: Sun, 06 Jun 2010 12:22:16 -0400
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4

I have added new create() methods to the reusable pool templates so it
can return pre-constructed (initialized) objects.  I also found a bug
internal to queueof lifo method and changed the templates for queueof
and stackof so that the pool is passed to the constructor rather than in
the template (linkage requirement issue).  Finally, I added an initial
unit test case, ucommonQueue (test/queue.cpp) which both demonstrates
the use case and validates at least some basic funcions of the current
implementation.  The unit test case code should be expanded upon to try
and identify any additional bugs or issues.

On 06/05/2010 03:51 PM, Leon Pollak wrote:
> On Saturday June 5 2010, David Sugar wrote:
>> 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)
> Hello David,
> 
> And again thanks for the example.
> 
> It seems you were right - no use of the queue/queueof was not tried yet...:-)
> 
> 1. I tried to compile the example you provided above. There is a problem with 
> the second template parameter of queueof - it cannot be null-pointer 
> according 
> to my search in the internet. See for example 
> http://stackoverflow.com/questions/1418019/casting-pointer-as-template-
> argument-comeau-msvc-compile-gcc-fails
> 
> 2. You declared all three objects as 'static', which, besides the problems 
> with compilation also makes them invisible from the outside, no? This forces 
> me to put both threads in the same file, which is not good for me.
> What was your reason to declare them static?
> 
> Thanks.

Attachment: dyfet.vcf
Description: Vcard


reply via email to

[Prev in Thread] Current Thread [Next in Thread]