Null-terminated Unicode strings in java.io on Windows

Krzysztof Żelechowski program.spe at home.pl
Fri Jan 25 17:42:23 UTC 2008


Dnia 25-01-2008, Pt o godzinie 17:30 +0000, Robert Lougher pisze:
> No it doesn't.  An implementation would have to be truly stupid to
> internally null-terminate.  How many Strings are in the heap?  How
> many will the programmer access via GetStringChars?  The null will be
> a overhead for all Strings for a miniscule percentage.

Please observe: 

1. 
the amount of memory needed to manage the allocation 
is greater than the number of bytes 
needed to store one additional character, 
so the relative impact on memory usage will not be dramatic.

2. The string usually has much more characters then one.
That means, if strings take 10 characters on the average, 
the overhead is 10%, in the impossible worst case, as explained below.
This is an overhead I (and most programmers) can live with.

3. Memory is allocated in chunks.  
The size and alignment of the chunk is subject to various limitations.
If the characters of the string do not fill the chunk entirely, 
there is good chance 
that there will space for the terminating zero anyway.

Yours truly,
Chris




More information about the core-libs-dev mailing list