Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Substring changes (JDK 1.7)

Reply
Thread Tools

Substring changes (JDK 1.7)

 
 
Jan Burse
Guest
Posts: n/a
 
      01-10-2013
Dear All,

> Recent versions of the JDK do not reuse the backing char[].
> The reason is that the offset and length fields have been
> removed from String to save memory.


Did this affect some of your code?

Bye
 
Reply With Quote
 
 
 
 
markspace
Guest
Posts: n/a
 
      01-10-2013
On 1/10/2013 5:38 AM, Jan Burse wrote:
> Dear All,
>
> > Recent versions of the JDK do not reuse the backing char[].
> > The reason is that the offset and length fields have been
> > removed from String to save memory.

>
> Did this affect some of your code?
>
> Bye



Wrong on both counts. Where did you read this nonsense?

<http://hg.openjdk.java.net/jdk7/jdk7-gate/jdk/file/tip/src/share/classes/java/lang/String.java>


 
Reply With Quote
 
 
 
 
Joshua Cranmer
Guest
Posts: n/a
 
      01-10-2013
On 1/10/2013 10:15 AM, markspace wrote:
> On 1/10/2013 5:38 AM, Jan Burse wrote:
>> Dear All,
>>
>> > Recent versions of the JDK do not reuse the backing char[].
>> > The reason is that the offset and length fields have been
>> > removed from String to save memory.

>>
>> Did this affect some of your code?
>>
>> Bye

>
>
> Wrong on both counts. Where did you read this nonsense?
>
> <http://hg.openjdk.java.net/jdk7/jdk7-gate/jdk/file/tip/src/share/classes/java/lang/String.java>


<http://hg.openjdk.java.net/jdk8/jdk8-gate/jdk/rev/2c773daa825d>
suggests differently...


--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      01-10-2013
On 1/10/2013 8:48 AM, Joshua Cranmer wrote:

>
> <http://hg.openjdk.java.net/jdk8/jdk8-gate/jdk/rev/2c773daa825d>
> suggests differently...



That's 8, not 7. If you're going to ask about JDK 8, don't put "JDK
1.7" in your subject title.


 
Reply With Quote
 
Lars Enderin
Guest
Posts: n/a
 
      01-10-2013
2013-01-10 18:22, markspace skrev:
> On 1/10/2013 8:48 AM, Joshua Cranmer wrote:
>
>>
>> <http://hg.openjdk.java.net/jdk8/jdk8-gate/jdk/rev/2c773daa825d>
>> suggests differently...

>
>
> That's 8, not 7. If you're going to ask about JDK 8, don't put "JDK
> 1.7" in your subject title.
>
>

The only question was in the OP. Jan Burse set the title, not Joshua.

--
Lars Enderin
 
Reply With Quote
 
Jan Burse
Guest
Posts: n/a
 
      01-10-2013
Jan Burse schrieb:
> Dear All,
>
> > Recent versions of the JDK do not reuse the backing char[].
> > The reason is that the offset and length fields have been
> > removed from String to save memory.

>
> Did this affect some of your code?
>
> Bye


Its from JDK 1.7 Update 10

Look see:

C:\Users\Jan Burse>java -version
java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b1
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

rt.jar:

public final class String
implements java.io.Serializable, Comparable<String>, CharSequence {
/** The value is used for character storage. */
private final char value[];

/** Cache the hash code for the string */
private int hash; // Default to 0

/** use serialVersionUID from JDK 1.0.2 for interoperability */
private static final long serialVersionUID = -6849794470754667710L;

-- and --

public String substring(int beginIndex, int endIndex) {
if (beginIndex < 0) {
throw new StringIndexOutOfBoundsException(beginIndex);
}
if (endIndex > value.length) {
throw new StringIndexOutOfBoundsException(endIndex);
}
int subLen = endIndex - beginIndex;
if (subLen < 0) {
throw new StringIndexOutOfBoundsException(subLen);
}
return ((beginIndex == 0) && (endIndex == value.length)) ? this
: new String(value, beginIndex, subLen);
}

-- and --

public String(char value[], int offset, int count) {
if (offset < 0) {
throw new StringIndexOutOfBoundsException(offset);
}
if (count < 0) {
throw new StringIndexOutOfBoundsException(count);
}
// Note: offset or count might be near -1>>>1.
if (offset > value.length - count) {
throw new StringIndexOutOfBoundsException(offset + count);
}
this.value = Arrays.copyOfRange(value, offset, offset+count);
}
 
Reply With Quote
 
Jan Burse
Guest
Posts: n/a
 
      01-10-2013
Hi,

It was originally observed in a Scala newsgroup:

why is String grouped() so slow?
https://groups.google.com/forum/?fro...er/D1qmblInfyg

Bye

Jan Burse schrieb:
> Jan Burse schrieb:
>> Dear All,
>>
>> > Recent versions of the JDK do not reuse the backing char[].
>> > The reason is that the offset and length fields have been
>> > removed from String to save memory.

>>
>> Did this affect some of your code?
>>
>> Bye

>
> Its from JDK 1.7 Update 10
>
> Look see:
>
> C:\Users\Jan Burse>java -version
> java version "1.7.0_10"
> Java(TM) SE Runtime Environment (build 1.7.0_10-b1
> Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
>
> rt.jar:


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-10-2013
On Thu, 10 Jan 2013 14:38:36 +0100, Jan Burse <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>
>Did this affect some of your code?


If this change happens, you would no longer consider using new String(
String) to unencumber a substring.

You no longer have to worry a about a tiny substring holding a meg+
sized base string around in memory.
--
Roedy Green Canadian Mind Products http://mindprod.com
Students who hire or con others to do their homework are as foolish
as couch potatoes who hire others to go to the gym for them.
 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      01-10-2013
On 10.01.2013 21:22, Roedy Green wrote:

> If this change happens, you would no longer consider using new String(
> String) to unencumber a substring.
>
> You no longer have to worry a about a tiny substring holding a meg+
> sized base string around in memory.


Instead you have to worry about tons of substrings drawn from the same
input String to occupy a lot more memory and slowing down GC. Trade
offs, trade offs...

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-10-2013
On Thu, 10 Jan 2013 22:58:24 +0100, Robert Klemme
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>Instead you have to worry about tons of substrings drawn from the same
>input String to occupy a lot more memory and slowing down GC. Trade
>offs, trade offs...


I wonder if it could work like this.

Perhaps GC could notice a giant string encumbered by a few small
strings, and could do a new String for you and gc the base string.

If you don't need the base string itself, I think most of the time you
are best off to do the new string.

For what I do, I am peeling off small strings from a big string which
represents a file image. I keep the big string to the last minute.
Encumbering works well for me.
--
Roedy Green Canadian Mind Products http://mindprod.com
Students who hire or con others to do their homework are as foolish
as couch potatoes who hire others to go to the gym for them.
 
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
Finding a SubString within a String Badass Scotsman ASP .Net 2 03-31-2006 04:00 PM
RegEx search for a substring within a substring colinhumber@gmail.com Perl Misc 3 08-03-2005 04:29 PM
find if there is a given substring inside a string juli ASP .Net 3 12-06-2004 11:52 AM
web sddress substring =?Utf-8?B?Sm9u?= ASP .Net 2 11-30-2004 01:31 PM
"Substring" for images? How do I determine if an image is contained within another? Sean Java 0 05-04-2004 05:50 PM



Advertisments