0

I am using Chronicle Bytes version 1.7.22. I would like to use Bytes for off-heap caching and persistence of large media (e.g. images, videos). Currently I am creating the Bytes as follows:

Bytes.elasticByteBuffer();

OR (for persistence)

MappedBytes.mappedBytes(file, 64);

I have used Bytes.outputStream() to write the media content and used Bytes.inputStream() to read the media content. However, I can only read the InputStream once. It does not seem to support reset. How can I read the media content multiple times and concurrently without allocation of extra memory?

Martin
  • 129
  • 1
  • 11

1 Answers1

0

I would suggest you upgrade to the latest 1.9.x version though thus wont fix you problem as such it will fix many bugs.

Bytes is intended to be single threaded however with care the underlying bytes can be shared. You need to create a BytesStore whuch has the shared data and wrap thus with a Bytes eg NativeBytes so you can have a thread local pointer to that data.

If you need to share how long the data is you must store that in the underlying bytes using a thread safe operation.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Should it basically work if I call Bytes.bytesForRead().inputStream() multiple times from a single thread? – Martin Nov 18 '17 at 08:58
  • new NativeBytes(Bytes).inputStream() results in "The constructor NativeBytes(BytesStore) is not visible". How can I wrap it? – Martin Nov 18 '17 at 11:28
  • This seems to do the basic job: new StreamingInputStream(new VanillaBytes(Bytes)). But, I run into some trouble: # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007f26c68c6474, pid=14796, tid=0x00007f26bee6a700 # # JRE version: OpenJDK Runtime Environment (8.0_111-b14) (build 1.8.0_111-8u111-b14-2~bpo8+1-b14) # Java VM: OpenJDK 64-Bit Server VM (25.111-b14 mixed mode linux-amd64 compressed oops) # Problematic frame: # J 9430 C2 net.openhft.chronicle.bytes.MappedBytesStore.readByte(J)B (212 bytes) – Martin Nov 18 '17 at 12:52
  • new VanillaBytes(Bytes).inputStream() is the solution. However, I struggled because of a potential bug of a copy method. Maybe also a larger chunk size makes sense (e.g. 4096). – Martin Nov 18 '17 at 20:17