現時点では、以下に示す関数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);
}
};