Archived

This topic is now archived and is closed to further replies.

Subconscious

Quick STL string question

Recommended Posts

What is the maximum length for an STL string? I tried googling and found many STL string tutorials, but none of the mentioned how long you can or should make them so I figured someone here would know. I ask because I want to know if it''s reasonable to store the whole text of a .ini file to an STL string so I can manipulate it? Will this work ok performance-wise and is there some kind of maximum character cap I should check for?

Share this post


Link to post
Share on other sites
The maximum size of std::string is implementation-dependent. You can ask your std::string implementating by calling the max_size() member function of std::string.

Share this post


Link to post
Share on other sites
Thanks for the info, I tried it out on my computer and the max is rediculously high, but I''m worried about just assuming it''s enough to hold 2k or so characters if I need to on every computer. Any ideas on a general range that it''s safe to assume any computer could handle? I''ll obviously check if max > file size, but I want to know if I should bother setting it up to go to multiple strings, or just have the method fail in the unlikely event that the max size is too small.

Share this post


Link to post
Share on other sites
2K characters is nothing to worry about, assuming your target platform is a personal computer. GBA, go ahead and worry, but for a Windows box, I wouldn''t worry about it unless you''re expecting to deal with files in the tens or hundreds of megabytes range. And even so, I wouldn''t be worrying that I overran the size of the string, I''d be worrying that my algorithm for processing the file needs work. In any case, the max size probably won''t vary from computer to computer; it should be set by the compiler you''re using.

Share this post


Link to post
Share on other sites
Also, the max_size of the string usually uses the max_size of the allocator. And then the max length depends on how much memory you have already allocated, and what allocator you are using.

Share this post


Link to post
Share on other sites