Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum string length (or size) that I can pass to function?

Tags:

c++

string

I have the following function:

int Foo(string sentence);

I want to know what is the maximum string length I could pass? I think it should depend on the stack size allocated to the function as this string will be copied to the stack, is that true? or it depends on string::max_size value? I'm using C++ under VS2010, windows7

EDIT. I need to have a copy as the function modifies the string contents.

like image 359
Ahmed Avatar asked Nov 29 '10 13:11

Ahmed


1 Answers

The std::string object will be copied onto the stack, but the string body will not - it will be allocated on heap. The actual limitation will depend on the system and program memory usage and can be something like from ten million to one billion charactes on a 32-bit system.

like image 150
sharptooth Avatar answered Sep 29 '22 08:09

sharptooth