Jump to content
  • Advertisement
Sign in to follow this  
Wavinator

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

This topic is 4908 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
std::string::max_size();
std::wstring::max_size();

Oe, more generally std::basic_string<char_type>::max_size();

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!