List Info

Thread: boost.python Handling python objects in c++ efficiently




boost.python Handling python objects in c++ efficiently
user name
2008-04-18 10:24:18
Hello,
 
I have a message queue and message handling system that is fed from python side and consumed by c++ side.
The messages are not independent so they have to be handled in order.
I go over the list every frame and handle the message objects one by one. The messages inherit from a common class and all message classes are exposed to python.
There are two problems. The first ;problem is when I add a new message I have to change my message manager code adding a few more lines to check type. (which seems ugly)
The second problem is that in order to assure the order of messages I go over the python list twice and I take objects using [] operator which is slow I think. ( I do this every frame and even if most of the time message queue is empty it is annoying)
Any help is appreciated.
 ;
the code looks like this (not same):
 
boost::python::list actList ;

actList=boost::python::extract<boost::python::list>; (actListObj);

int len=boost::python::len(actList);

for

(int i=0;i<len;i++)

{

boost::python::object cur = actList[i];

boost::python::extract<Message1&> m1 (cur);

if

(m1.check()) {

activeHandlers.push_back(

new Message1Handler(m1(), params);

continue;

}

boost::python::extract<Message2&> m2 (cur);

if

(m2.check()) {

activeHandlers.push_back(

new Message2Handler(m1(), params);

continue;

}

}

// finally clear the list

for

(int i=0;i<len;i++)

{

actList.pop();

}



--
Furkan Kuru
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )