String size limit in C ++?

I have a million entries, each containing about 30 characters. Can I read all this on one line? Is there a line size limit that I can highlight?

If so, can I somehow send data on socket records by record and get its record by record. I do not know the size of each record until runtime.

+7
c ++
source share
8 answers

To answer your first question: maximum C ++ string size specified by string :: max_size

+16
source share

std::string::max_size() will tell you the theoretical limit imposed by the architecture of your program. In addition, if you have enough space for RAM and / or disk space, you can have huge std::strings . The answer to your second question: yes, you can send a record by record, in addition, you can not send large chunks of data via a socket right away - there are restrictions on the size of one send operation. The fact that the size of one line is unknown until the runtime is a problem, at compile time you do not need to know it to send them over the socket. How to actually send these line records by record depends on which socket / network library you are using; refer to the relevant documentation.

+8
source share

The only practical limit on line size in C ++ is your available memory. In this case, it would be expensive to redistribute the row to the desired size, since you continue to receive data (provided that you do not know its total size in advance). Usually you read chunks of data into a fixed-size buffer and decode it into its natural form (your records) as it is received.

+4
source share

There is no official line size limit. The software will query your system for memory, and while it receives it, it will be able to add characters to your string.

The rest of your question is not clear.

+2
source share

The size of the line is limited only by the amount of memory available to the program, this is more of a limitation of the operating system than a limit of C ++. C ++ / C lines end in zero, so string procedures will successfully process extremely long lines until they find zero.

In Win32, the maximum available memory for data is usually around 2 gigs.

You can read arbitrarily large amounts of data from a socket, but you should have some way to distinguish between the data you read. There should be an end to the record marker or the length associated with the records you are reading, and use them to analyze the records. Are you sure you want to read the data in a string? What happens if you do not have enough free memory to store data in RAM? I suspect there is a more efficient way to process this data, but I do not know enough about the problem.

+2
source share

In theory, no. But do not allocate 100 GB of memory, because the user probably will not have so much RAM. If you use std :: strings, the maximum size is std :: string :: npos.

+1
source share

How to send them in a different format?

on your server: send (STRLEN (szRecordServer)); send (szRecordServer);

in your client: RECV (cbRecord); Alloc (szRecordClient); RECV (szRecordClient);

and repeat it a million times.

0
source share

If we're talking about char* , you're limited to about 2 ^ 32 on 32-bit systems and with 64-bit 64-bit versions

with 2 ^ 64 (unexpected)

Update: This is incorrect. See Comments

-one
source share

All Articles