C ++指针使用多少内存? [英] How much memory does a C++ pointer use?

查看:192
本文介绍了C ++指针使用多少内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做(可能是错误的)假设,它是实现和/或系统依赖。是否有像INT_MAX或CHAR_BIT这样的东西可以告诉我内存中指针的大小?

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 pointer in memory?

推荐答案

指针指向一个地方在内存中,因此在32位系统上为32位,在64位系统中为64位。

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.

指针大小也与其指向的类型无关at,可以通过 sizeof(anyType *)

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

>

UPD

我回答这个问题的方式是由问题的方式提出的(建议一个简单的答案)。是的,我同意,在像指向虚拟方法表的情况下,指针的大小会有所不同,根据本文,它将根据不同的平台,甚至在不同的编译器在同一平台内变化。在我的情况下,例如(x64 ubuntu,GCC 4.6.3)它等于16字节。

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.

这篇关于C ++指针使用多少内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆