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?
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.
精彩评论