Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure, that new Buffer views are used in PrimitiveBlocks from BufferAccess #368

Open
tpietzsch opened this issue Sep 14, 2024 · 0 comments

Comments

@tpietzsch
Copy link
Member

MemCopy implementations that copy from/to Buffers currently use the stateful Buffer APIs, e.g.

class MemCopyByteBufferToArray implements MemCopy< ByteBuffer, byte[] >
{
@Override
public void copyForward( final ByteBuffer src, final int srcPos, final byte[] dest, final int destPos, final int length )
{
src.position( srcPos );
src.get( dest, destPos, length );
}

To make sure this works in multi-threaded scenarios, new Buffer views should be used in every PrimitiveBlocks instance.
For example, this

final S src = ( S ) ( ( ArrayDataAccess< ? > ) cellAccess.get().getData() ).getCurrentStorageArray();

should be something like

final S src = ( S ) ( ( ArrayDataAccess< ? > ) cellAccess.get().getData().createView( this ) ).getCurrentStorageArray();

Alternatively, we should make sure that createView() is called when getting the BufferAccess from an image. (For example, for ArrayImg that should be already the case.)

Even better would be to move to Java 9+, where absolute bulk put/get methods are available in Buffer and we can avoid the stateful API in MemCopy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant