LoginSignup
4
3

More than 5 years have passed since last update.

std::functionって大きいね

Last updated at Posted at 2015-06-11

 関数ポインタ書くの面倒なので、std::functionにする場合、当たり前だけどstd::functionの方が大きいので注意が必要なんすね。
 イージング関数をメンバー関数ポインタに代入しといて~、オブジェクトの移動をイージング関数で制御して~みたいな場合だと関数ポインタにした方が良い場合がありそうっすね。


#include <iostream>
#include <functional>

int main()
{
    std::cout << sizeof(std::function<int()>) << std::endl;
    std::cout << sizeof(int(*)()) << std::endl;
}

MSVCだと、40、4。
clangだと、48、8。
gccだと、32、8。
という結果になったよ。MSVCだけ小さいのは64bitと32bitの違いとかかな?

clangとgccはここで調べたよ

参考にしたよ

関数ポインタよりもstd::functionを使おう

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3