len3d

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

never use virtual function for primitives!
why?
they are memory-consuming!
each primitive will contain a table of virtual function pointers, and you will usually have a river of primitives!
so, use virtual function for primitive operator instead! this balance the design and the performance!
treat primitives together as stream,
like this:

class primtive {
};

class primitiveOperator {
public:
virtual void dosomething( void *pointer_to_primitive_array, int num_of_primitives, void *outputs );
...
};

while programming, we can dynamically bind a specified primitive operator to an array of primitives, and the indirect call to the virtual function will only happen once, not one time for each primitive access!


posted on 2008-04-17 21:52  Len3d  阅读(245)  评论(0)    收藏  举报