Absolute index bulk put/get byte operations on ByteBuffer

Alan Bateman Alan.Bateman at oracle.com
Fri Sep 7 10:43:24 UTC 2018


On 06/09/2018 20:42, Martin Thompson wrote:
> There has been a long outstanding issue of ByteBuffer not having 
> methods to get or put a ByteBuffer or byte[] at an absolute index.
>
> https://bugs.openjdk.java.net/browse/JDK-5029431
>
> This seriously hampers the usefulness of ByteBuffer in a concurrent 
> environment due to contention on the position and limit fields. 
> Slicing or duplicating are not valid options are this are not 
> threadsafe and they allocate.
>
> Is there any reason why this bug has not been progressed?
Many of the calls for absolute operations on ByteBuffers over the years 
have really been cases where someone wanted to operate on a region of 
memory and ended up using a direct buffer because they didn't have 
anything better. The buffer position/limit get in the way in many of 
these cases of course.

As regards JDK-5029431 then I think these methods should have been added 
a long time ago but adding them now does beg the question as to how 
ByteBuffers will interact with memory regions or similar concept that 
Project Panama may introduce. There is also the question of addressing 
with large files (mapping regions > 2GB). Stuart might want to comment 
on this as I think he has concerns about adding further methods here 
until some of these other interactions are worked out.

-Alan


More information about the nio-dev mailing list