Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

New write() Methods in Bytes #54

Closed
pjulien opened this issue Jan 17, 2015 · 6 comments
Closed

New write() Methods in Bytes #54

pjulien opened this issue Jan 17, 2015 · 6 comments

Comments

@pjulien
Copy link

pjulien commented Jan 17, 2015

Please consider adding positional buffer write methods to NativeBytes. Currently the only available method that comes close is:

    void write(long offset, byte[] bytes, int off, int len);

However I am writing lock free many to one and one to many ring buffers. Not having a positional index makes it very difficult because I can't use/move the position of any of the buffers.

If the following write methods

  void write(long offset, ByteBuffer bytes, int off, int len);
  void write(long offset, Bytes bytes, int off, int len);

were added it would make this use case possible.

I have the same problem for reading, I am using buffers but only byte[] is supported via:

void readFully(long offset, @NotNull byte[] bytes, int off, int len);
@peter-lawrey
Copy link
Member

Can you not set the position and limit of the ByteBuffer and Bytes when you
read/write?
On 17/01/2015 5:18 PM, "Patrick Julien" [email protected] wrote:

Please consider adding positional buffer write methods to NativeBytes.
Currently the only available method that comes close is:

void write(long offset, byte[] bytes, int off, int len);

However I am writing lock free many to one and one to many ring buffers.
Not having a positional index makes it very difficult because I can't
use/move the position of any of the buffers.

If the following write methods

void write(long offset, ByteBuffer bytes, int off, int len);
void write(long offset, Bytes bytes, int off, int len);

were added it would make this use case possible.

I have the same problem for reading, I am using buffers but only byte[]
is supported via:

void readFully(long offset, @NotNull byte[] bytes, int off, int len);


Reply to this email directly or view it on GitHub
#54.

@pjulien
Copy link
Author

pjulien commented Jan 17, 2015

Can you not set the position and limit of the ByteBuffer and Bytes when you
read/write?

The buffer backing the ring buffer is visible to multiple writers and a reader. So no, I cannot.

I could change the position and limit of the source buffer when writing into the ring buffer but I would still be unable to read back from this buffer when it comes time to read from it.

@leventov
Copy link
Member

BTW you can use MultiStoreBytes to solve the problem right now. But I agree such methods would be useful.

@peter-lawrey
Copy link
Member

I agree the methods would be useful. Btw you can take a ByteBuffer.slice ()
or Bytes.bytes () of a buffer and access the same memory using different
positions and limits.
On 17/01/2015 9:20 PM, "Patrick Julien" [email protected] wrote:

Can you not set the position and limit of the ByteBuffer and Bytes when you
read/write?

The buffer backing the ring buffer is visible to multiple writers and a
reader. So no, I cannot.

I could change the position and limit of the source buffer when writing
into the ring buffer but I would still be unable to read back from this
buffer when it comes time to read from it.


Reply to this email directly or view it on GitHub
#54 (comment).

@pjulien
Copy link
Author

pjulien commented Jan 18, 2015

Thank you for your suggestions but I am trying to stay allocation free in this part of the system. I am there other than for this call.

@peter-lawrey
Copy link
Member

These functions have been added to Chronicle Bytes

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

No branches or pull requests

3 participants