What is the cost of sizeof?

前端 未结 7 1669
一向
一向 2021-02-05 10:06

What is the cost of sizeof?

I would expect:

  • sizeof(someclass) can be known at compile time
  • sizeof(someStaticArray) can be known at compile time
7条回答
  •  走了就别回头了
    2021-02-05 10:49

    There is zero runtime cost. In the case of dynamically allocated memory, sizeof gives the size of the static pointer object, not the dynamically allocated memory.

提交回复
热议问题