| Author |
maximum size of String
|
sakuja jangra
Greenhorn
Joined: Dec 18, 2006
Posts: 6
|
|
hi all, I have got a condition where I have to pass a string to a web service. ealier this service was accepting parameter as CSV file but now that's taking that parameter as String. I have to pass the String with the condition that size of String cant be greater than 80 MB. I know this is bad design but cant think of any other option at present(due to time constraint and contract with the web service). My question is how can we decide the size of String doesn't cross 80 MB(It can be somewhat less for that matter). I hope that is based on JVM allocation of memory. but I want that independant of that. I searched internet but couldn't find any pointer towards that. Please help. thanks in advance.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
|
Please reserve this forum for adbanced Java questions. I have moved this post to a more appropriate forum.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8259
|
|
|
I'm not aware of any defined limit but String.length() returns an int, so the length is practically limited to Integer.MAX_VALUE (give or take for encoding). If you are seeing an OutOfMemoryError, that's because the default heap size for the JVM is 64 Megs. You can control the heap size through the -Xmx command line parameter described here.
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16479
|
|
|
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
|
Within the JVM, each char in a String requires two bytes- -so Paul's answer requires an extra factor of two. However if you're not sure that the JVM memory usage is what's required here, then several other answers are possible. Possibly your clients want to know that the string content will fit in a file with maximum size 80 Mb, for example. If that's the case, you would need to know what type of file encoding is used. And if the encoding is a variable-length encoding such as UTF-8, then different chars require different numbers of bytes (from 1-3 each) and you would need to know about the content of each String in order to answer this question. So, I think you need to find out where this requirement is really coming from, and what exactly they think it means.
|
"I'm not back." - Bill Harding, Twister
|
 |
sakuja jangra
Greenhorn
Joined: Dec 18, 2006
Posts: 6
|
|
|
Thanks guys.
|
 |
 |
|
|
subject: maximum size of String
|
|
|