|
From: | Leon Pollak |
Subject: | Re: HowTo for queues - open issues resolved in 3.0.1 |
Date: | Tue, 8 Jun 2010 15:15:46 +0300 |
User-agent: | KMail/1.13.3 (Linux/2.6.33.5-112.fc13.x86_64; KDE/4.4.3; x86_64; ; ) |
On Sunday June 6 2010, David Sugar wrote: > 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. David, I downloaded the SVN head - the problem 1 from the letter below still exists. I also do not see that file queue.cpp is compiled by the tests. May be I use incorrect SVN? svn co svn://svn.sv.gnu.org/commoncpp/trunk/ucommon Thanks. > > 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. -- Dr.Leon M.Pollak Director PLR Information Systems Ltd. Tel.:+972-98657670 | POB 8130, H'Aomanut 9, Fax.:+972-98657621 | Poleg Industrial Zone, Mob.:+972-544739246 | Netanya, 42160, Israel. |
[Prev in Thread] | Current Thread | [Next in Thread] |