Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSimonForsman

Posted 16 May 2013 - 09:45 AM

You should use the StringBuffer(threadsafe) or StringBuilder(not threadsafe, usually faster than StringBuffer) class instead, Strings in Java are immutable and cannot be modified (any operation that modifies strings will create a new string (This is both slow and can trigger garbage collection). alternativly keep the constant parts of the text as separate strings and print them after eachother.

Calling toString on the StringBuilder/Buffer will however create a new String object, so if you can, use the getChars method to copy the builders buffer to a buffer you use to print from. (This only works if your text renderer can render a character buffer and not just strings Edit: also, if you do copy to a buffer, make sure you only allocate that buffer once (if you allocate the buffer each time you copy to it you gain nothing)

#6SimonForsman

Posted 16 May 2013 - 08:32 AM

You should use the StringBuffer(threadsafe) or StringBuilder(not threadsafe, usually faster than StringBuffer) class instead, Strings in Java are immutable and cannot be modified (any operation that modifies strings will create a new string (This is both slow and can trigger garbage collection). alternativly keep the constant parts of the text as separate strings and print them after eachother.

 

Calling toString on the StringBuilder/Buffer will however create a new String object, so if you can, use the getChars method to copy the builders buffer to a buffer you use to print from. (This only works if your text renderer can render a character buffer and not just strings)


#5SimonForsman

Posted 16 May 2013 - 08:07 AM

You should use the StringBuffer(threadsafe) or StringBuilder(not threadsafe, usually faster than StringBuffer) class instead, Strings in Java are immutable and cannot be modified (any operation that modifies strings will create a new string (This is both slow and can trigger garbage collection). alternativly keep the constant parts of the text as separate strings and print them after eachother.

 

Calling toString on the StringBuilder/Buffer will however create a new String object, so if you can, use the getChars method to copy the builders buffer to a buffer you use to print from. (This only works if your text renderer can render a character buffer and not just strings)


#4SimonForsman

Posted 16 May 2013 - 08:01 AM

You should use the StringBuffer(threadsafe) or StringBuilder(not threadsafe, usually faster than StringBuffer) class instead, Strings in Java are immutable and cannot be modified (any operation that modifies strings will create a new string (This is both slow and can trigger garbage collection). alternativly keep the constant parts of the text as separate strings and print them after eachother.


#3SimonForsman

Posted 16 May 2013 - 08:00 AM

You should use the StringBuffer(threadsafe) or StringBuilder(not threadsafe) class instead, Strings in Java are immutable and cannot be modified (any operation that modifies strings will create a new string (This is both slow and can trigger garbage collection). alternativly keep the constant parts of the text as separate strings and print them after eachother.


#2SimonForsman

Posted 16 May 2013 - 07:58 AM

You should use the StringBuffer class instead, Strings in Java are immutable and cannot be modified (any operation that modifies strings will create a new string). (StringBuilder might be worth looking at as well)


PARTNERS