How much memory does a C++ pointer use?

前端 未结 6 1843
南方客
南方客 2020-12-17 10:54

I\'m making the (possibly wrong) assumption that it is implementation and/or system dependent. Is there something like INT_MAX or CHAR_BIT that would tell me the size of a p

6条回答
  •  情歌与酒
    2020-12-17 11:20

    A pointer points into a place in memory, so it would be 32 bits on a 32-bit system, and 64 bits in 64-bit system.

    Pointer size is also irrelevant to the type it points at, and can be measured by sizeof(anyType*)

    UPD

    The way I answered this was suggested by the way the question was asked (which suggested a simple answer). Yes, I do agree that in cases like pointers to virtual method table, the size of the pointer will differ, and according to this article, it will vary on different platforms and even on different compilers within the same platform. In my case, for example (x64 ubuntu, GCC 4.6.3) it equals to 16 bytes.

提交回复
热议问题