Null-terminated Unicode strings in java.io on Windows
program.spe at home.pl
Fri Jan 25 18:18:34 UTC 2008
Dnia 25-01-2008, Pt o godzinie 18:44 +0100, Roman Kennke pisze:
> > > The specification is buggy
> > > > in that it does not take into account the operating system interface
> > > > and makes correct memory management inefficient
> > > > for the benefit of sparing one byte per buffer
> > > > where an OS call is not needed.
> > > > Ridiculous.
> > >
> > > Tom Tromey pointed out another possible problem on IRC: What if the
> > > string itself contains the 0? Unlikely, but possible in the Java world.
> > I understand that parameters passed to the OS
> > are subject to the limitations of the OS.
> > Not containing a zero inside may be just one of them.
> > The Java specification claims nowhere
> > that every string can be used to name every object.
> Yeah, but GetStringChars() is a general purpuse JNI function and not at
> all tied to the OS. Passing the string on to the OS for I/O purposes is
> just one use case. Zero-terminating a Java string really doesn't right.
> If you need it zero-terminated, then you can always do this in your code
> by copying over the string in a static buffer or similar (as suggested
> somewhere else in this thread). This is by no means incorrect memory
> management, it only requires a little more thinking.
Static buffers are not reëntrant and unwieldy:
they are either too large or too small.
It has been argued that excessive copying is inefficient
and can be easily avoided with proper setup.
More information about the core-libs-dev