【发布时间】:2012-10-28 23:25:09
【问题描述】:
我的这段代码由于锁定而面临性能问题。请参阅下面的草图(无论如何不能发布太大的实际代码):
XYZ::process()
{
...
lock();
processSharedData(id );
unlock();
...
}
XYZ::processSharedData(obj id)
{
obj a = accessDataAttr1(id);
//do some integrity checks
//evaluate some conditions and then
func1(attr1, attr2, attr3, ...);
obj b = accessDataAttr2(id);
//do some integrity checks
//evaluate some conditions and then
func2(attr1, attr2, attr3, ...);
obj c = accessDataAttr3(id);
//do some integrity checks
//evaluate some conditions and then
func3(attr1, attr2, attr3, ...);
//do some clean up
return;
}
现在我想将 func1、func2 和 func3 从锁定/解锁范围中移出。请提出有效的方法。有没有办法用它的参数存储函数调用以便以后调用它?
如何将所有参数存储在成员结构中,将函数指针存储在 std::list 中?
编辑:
很抱歉在我还没有 c++11 之前没有提到这一点。任何没有 std:function 和 std:bind 的解决方案现在都很好。
【问题讨论】:
-
不能使用它们。请参阅我的 cmets 了解其他帖子。