*
The moose likes Java in General and the fly likes Max size of data a string variable can hold? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Max size of data a string variable can hold?" Watch "Max size of data a string variable can hold?" New topic
Author

Max size of data a string variable can hold?

john klucas
Greenhorn

Joined: Jul 31, 2001
Posts: 23
Can any one tell me, what i have to do if the String Object holds data more than 20-22MB of data.
The string object holds that much of data and then the same data have to be displayed in a text area.
i am doing something like this:

private void doReadFile(BufferedReader fileReader) {
String strial = "";
String s = "";
try{
if(fileReader != null)
{
ivjTextArea1.append("One Moment Please.....");
while ((s=fileReader.readLine()) != null)
{
temptrial.append(s+"\n");
}
strial = temptrial.toString();
ivjTextArea1.setText(temptrial.toString());
fileReader.close();
}
} catch(Throwable exception){
handleException(exception);
}
}
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Please don't post the exact same question in multiple forums. You just waste peoples time.
john klucas
Greenhorn

Joined: Jul 31, 2001
Posts: 23
i will really appreciate if any one answers to my question.
i did post it twice, bcoz there was no reply.
Anyway soory for posting it twice.]
Can any one answer please.
Urgent please.
James Gray
Ranch Hand

Joined: Sep 10, 2001
Posts: 30
I'm not sure I totally understand the question, but as far as I know the size of a String is limited only by the resources of the machine.
Looking at your code, my biggest suggestion would be to use TextArea's append() method directly. Hope that helps.
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
That is probably a bad idea.
Depending on the JVM implementation, it is likely that creating a 22MB string will attempt to create a contiguous chunk of memory on the heap. This will probably result in swapping, and the performance of your application will be crap.
If you are doing a lot of string manipulations, it will be even worse. Every time you do change the string, it will try to allocate another 22MB to hold the changed data. You could have the VM holding on to hundreds of MB at once.
Think about what you are trying to achieve. If you are writing a text editor, for instance, maybe holding each line in a separate string is the best approach.
Java has great features for memory management (like automatic GC), but you still need to understand basic computer science principles if you want to write efficient code.


Sun Certified Programmer for the Java 2 Platform
Dragon Liu
Greenhorn

Joined: Sep 12, 2001
Posts: 22
Geoffrey Falk:
I agree with you very much!

Hello,This is my question
 
Don't get me started about those stupid light bulbs.
 
subject: Max size of data a string variable can hold?
 
Similar Threads
Unusual FileNotFoundException error
Max string size?
Case Insensative search
Case Insensative search
Search Function for a TextArea.