size_t 的点
可能的重复:
无符号整数与 size_t
当我需要存储某些东西的大小(通常是分配的东西)使用 new
),我总是将其存储在 unsigned int
中。然而,浏览一些代码时,我看到使用了 size_t
。根据 this,它几乎没有被大量使用。
- C++ 中的
size_t
有什么意义? - 为什么使用它的少数函数不直接使用
unsigned int
来代替? - 在新代码中应该如何使用它?
Possible Duplicate:
unsigned int vs. size_t
When I need to store the size of something (usually stuff allocated with new
), I always store it in an unsigned int
. Browsing through some code, however, I saw size_t
used. According to this, it's hardly used for a lot.
- What is the point of
size_t
in C++? - Why don't those few functions that use it just use an
unsigned int
instead? - How should it be used in new code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能有一个数组,其大小和索引可能超出 int 的范围,因为 int 只能保证 16 位。目前使用 size_t 的实用性相当低,但将来可能会变得更加重要。例如,在针对 64 位进行 MSVC 编译时,我可以有一个类,其实例大于 4GB。当然,我预计实际上 CRT 不会处理那么大的尺寸,但标准对此并不关心。
You could have an array, the size and indexing of which can exceed the range of an int, as an int is only guaranteed 16bits. The practicality of using size_t is rather low right now but may become more important in the future. On MSVC compiling for 64bit, for example, I could have a class, an instance of which is larger than 4GB. Of course, I expect that in practicality, the CRT won't deal with sizes that large, but the Standard is unconcerned with that.