473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

C++'s std::string max length

Xx r3negade
I'm making a socket that retrieves several thousand bytes of data from a web page and then parses it. The parsing is done using functions included in std::string. The problem is that std::string can only hold so much data. What are some ways to work around this problem?
Aug 1 '08 #1
3 7737
gpraghuram
1,275 Expert 1GB
Why cant you use char* and allocate memory dynamically depending on the input you are getting....
By the way what is the size restriction on std::string?
Raghu
Aug 1 '08 #2
Banfa
9,065 Expert Mod 8TB
and what is the size of the data you are trying to put into it.
Aug 1 '08 #3
Sirmont
12
std strings, like any other std containers, have a max length defined by max_size(). In general, this length is 2^32 on 32 bit machines (which means 4 gigabytes of data, should we consider std::strings to contain chars for simplification purposes).

So I doubt that your website contains 4GB of HTTP/HTML data on a single HTTP request. I therefore suspect that you're problem is elsewhere.

But should you work with data exceeding this limit (which is a very big problem considering that your process can't handle more than ~3.2GB of memory on a 32 bit machine, but that's another story), you should probably re-consider the architecture of your application to use streams that process data as it comes in, instead of downloading the full `file` before processing it...

Take a look at iostreams, stringstream, etc.

Hope this helped!
Aug 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

24
by: Julie | last post by:
I'm re-evaluating the way that I convert from a std::string to char *. (Requirement: the source is a std::string, the usable contents are char *) Here is what I've come up with: #include...
18
by: JKop | last post by:
Can some-one please point me to a nice site that gives an exhaustive list of all the memberfunctions, membervariables, operators, etc. of the std::string class, along with an informative...
1
by: Tero Toivanen | last post by:
Dear experts, I am doing code to Solaris 9 system with C++. I get every now and then segmentation fault in the following code that removes heading and trailing white spaces (mLineStr is of...
3
by: Mathieu Malaterre | last post by:
Hello, I guess this might be a very dummy question, but I couldn't find an answer in the group's archive. I am reading DICOM files, and to store the string read I use std::string....
16
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
3
by: jl_post | last post by:
Hi, I recently wrote two benchmark programs that compared if two strings were equal: one was a C program that used C char arrays with strcmp(), and the other was a C++ program that used...
7
by: Marcus Kwok | last post by:
std::string::npos is described in _TC++PL:SE_ (Section 20.3.4) as the "all characters" marker. I tried to use it this way, but my program crashes: #include <iostream> #include <string> int...
4
by: daroman | last post by:
Hi Guys, i've problem with my small C++ programm. I've just small template class which represetns a array, everything works fine up to combination with std::string. I did tried it with M$ VC++ and...
5
by: Stefan Naewe | last post by:
A simple test: <----------------------------> #include <string> #include <iostream> int main() { std::string h("Hello "); *h.rbegin() = '\0';
1
by: Pradeep | last post by:
Hi All, I am facing an issue where length method of std::string class gives a junk value when used in a expression. Here's an example. The code should not go into the for loop but it does...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.