Quick STL string question

Started by
7 comments, last by Subconscious 19 years, 11 months ago
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?
Advertisement
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.
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.
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.
Thanks for the quick and helpful info
I wouldn''t even bother with max_size(), just try it and see if you get a memory allocation exception.
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.
On a PC, you''re good for a gig.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
So, what''s the good of rope?

blah blah blah.

This topic is closed to new replies.

Advertisement