存储完整的通用函数调用以便稍后播放?
目前,我正在通过下面介绍的函数 MyClass::Enable 存储函数调用。它是通用的,因为我稍后可以通过循环 commanList 在消费者线程上播放该函数,而不必提供任何函数参数。
然而,通过快速性能检查,与使用函数查找表(这会破坏通用部分)并存储函数参数以及函数查找位置相比,此方法完成存储函数所需的处理时间要长 2 倍。 (如果这没有意义,我深表歉意:它本质上是一个函数记录器)。
是否有性能更友好的 std::tr1::bind [boost::bind] 版本,或者是否有更好的方法以通用方式记录函数调用并稍后回放?
class CVertexFormatGLPtr
{
void Enable(size_t a, size_t b);
void Disable();
};
class MyClass
{
public:
typedef std::function<void ()> command;
typedef std::list<command> commandList;
// This is a typedef of CVertexFormatPtr & CVertexFormatGLPtr
VertexFormatMap& m_vertexFormats;
void Enable(const CVertexFormatPtr& pVFormat, size_t a, size_t b)
{
// search to find if vertex buffer is active
auto itor = m_vertexFormats.find(pVFormat);
CVertexFormatGLPtr pVFormatGL = CVertexFormatGLPtr();
if ( itor != m_vertexFormats.end() )
{
pVFormatGL = (*itor).second;
}
std::function<void()> zeroArg = std::bind(&CVertexFormatGL::Enable, pVFormatGL, a, b);
m_renderCommands.push_back(zeroArg);
}
};
At the moment I am storing a function call via the function MyClass::Enable that I've presented below. It's generic in the sense that I can later play the function back on a consumer thread by looping through the commanList and not have to provide any function arguments.
However through a quick performance check this method takes 2x longer in processing time to complete the stored function when compared to using a function lookup table (which breaks the generic part) and storing the function arguments as well as the function lookup position. (apologies if this does not make sense : its essentially a function recorder).
Is there a more performance friendly version of std::tr1::bind [boost::bind], or is there a better way of recording a function call in a generic manner and playing it back later ?
class CVertexFormatGLPtr
{
void Enable(size_t a, size_t b);
void Disable();
};
class MyClass
{
public:
typedef std::function<void ()> command;
typedef std::list<command> commandList;
// This is a typedef of CVertexFormatPtr & CVertexFormatGLPtr
VertexFormatMap& m_vertexFormats;
void Enable(const CVertexFormatPtr& pVFormat, size_t a, size_t b)
{
// search to find if vertex buffer is active
auto itor = m_vertexFormats.find(pVFormat);
CVertexFormatGLPtr pVFormatGL = CVertexFormatGLPtr();
if ( itor != m_vertexFormats.end() )
{
pVFormatGL = (*itor).second;
}
std::function<void()> zeroArg = std::bind(&CVertexFormatGL::Enable, pVFormatGL, a, b);
m_renderCommands.push_back(zeroArg);
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论