Sign in to follow this  
Wavinator

[.net] String Data Type's range in C++

Recommended Posts

Can anyone point me to a ref for the character limit for a String type in C++? I found a reference on MSDN that indicates a 2 billion Unicode character limit. But it was under a Visual Basic specific section, so I'm suspicious. Google was not my friend for whatever reason, turning up hundreds of irrelevant replies. Oddly enough, MS didn't see fit to store this range in the table that lists String and all the other .NET data types, which DO have ranges. o_O

Share this post


Link to post
Share on other sites
And if you mean the System.String type in Managed C++ or C++/CLI, then the theoretical limit is the maximum value of a signed 32 bit integer: about 2 billion. However, in practice, it is limited by the systems virtual memory and/or address fragmentation.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
And if you mean the System.String type in Managed C++ or C++/CLI, then the theoretical limit is the maximum value of a signed 32 bit integer: about 2 billion. However, in practice, it is limited by the systems virtual memory and/or address fragmentation.


Thanks, this was the one I was looking for. What's really funny is that on the exact same table the range of an Int32 is spelled out in precise detail, but String is left completely blank.

The MSDN docs are so crappy!

Share this post


Link to post
Share on other sites
Quote:
Original post by Wavinator
What's really funny is that on the exact same table the range of an Int32 is spelled out in precise detail, but String is left completely blank.


Well, the difference is that an Int32 only takes a constant 4 bytes of memory, whereas a String takes 1 byte per character, up to the "theoretical" 231 limit. On a 32-bit system, your virtual address space is limited to 2GB anyway and it's usually quite fragmented so you're unlikely to even get close to that limit (even if you've got 16GB of RAM).

It's different when you're running on 64-bit Windows, but for the time being at least, you're going to have to work with the lowest-common-denominator of 32-bit.

What do you need to know the maximum for anyway?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this