Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Memory Leaks & Strings

Reply
Thread Tools

Re: Memory Leaks & Strings

 
 
Steven
Guest
Posts: n/a
 
      08-14-2003

"Chris Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed).. .

> String.valueOf(preferredSize), but that object is short-lived and will
> go away very soon. The primary advantage of String.valueOf is that it's
> simpler and more straight-forward, not that it is faster.
>


preferredSize+"" will generally do this:

String.operator+(preferredSize, "");

Java will call an implemented function, called the +operator and will pass 2
parameters of which 1 is of type double and the other one is an empty string
which has the size of 1 stopbyte (0x00).

the operator+() function will do this:

convert preferredSize (type double) into a string:

String pSize = String.valueOf(preferredSize);

and then append the empty string of size 1 to the end of pSize.

pSize.append("")

and then:

return pSize;

(33 + "")

will return "33"

This is the same as String.valueof(33)

this will return "33"

Note that "33"[3] == 0x00 (stop byte)

String.valueof(33) will definately be faster then (33+"") as (33+"") is
essentially the same as String.valueOf(33), but you need to append an empty
string to it.

It will not be very much faster thought.

> --
> www.designacourse.com
> The Easiest Way to Train Anyone... Anywhere.
>
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation



 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      08-15-2003
Steven wrote:
> "Chris Smith" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed).. .
>
> > String.valueOf(preferredSize), but that object is short-lived and will
> > go away very soon. The primary advantage of String.valueOf is that it's
> > simpler and more straight-forward, not that it is faster.

>
> preferredSize+"" will generally do this:
>
> String.operator+(preferredSize, "");
>
> Java will call an implemented function, called the +operator and will pass 2
> parameters of which 1 is of type double and the other one is an empty string
> which has the size of 1 stopbyte (0x00).
>
> [... and more ...]


I don't know where you're getting this from, but a lot of it is wrong.
I'm allowing for your use of C++ operator overloading syntax just out of
preference, though it's not very correct to say that String
concatenation is implemented in a function, when the language spec
clearly states that it will be replaced by a specific equivalent use of
the StringBuffer API at compile-time without generating a method call to
any method that's specific to String concatenation or that operates on
the String data type.

Nevertheless, it's incorrect to refer to a String as null-terminated in
Java, and to say that the left-hand side of a String concatenation is
converted into a String if it isn't one (it's actually converted into a
StringBuffer, or perhaps just passed directly into StringBuffer.append
of a StringBuffer that was created empty; either works fine).

In the end, yes String.valueOf will probably be faster, exactly as I
said (and you snipped) originally. However, you've got quite a few
things wrong about the reasoning behind it, and it really just doesn't
matter.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
Re: Memory Leaks & Strings Steven Java 1 08-15-2003 01:05 AM
Re: Memory Leaks & Strings Harald Hein Java 1 07-31-2003 11:39 AM
Re: Memory Leaks & Strings Jon Skeet Java 0 07-30-2003 02:47 PM
memory leaks with firebird? astromannix Firefox 2 07-26-2003 12:10 AM



Advertisments