What is the cost of sizeof?

前端 未结 7 1671
一向
一向 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:29

    sizeof only works at compile time. A dynamic array will use a pointer to dynamically allocated memory which will not be included in the result. You'll only get the size of the pointer and housekeeping information (array length, etc).

提交回复
热议问题