Questions tagged [bytebuffer]

A binary buffer with no specific encoding. Use this tag only if you're having specific problems in relation with byte buffers

A binary buffer with no specific encoding.

Examples include byte[] in Java, char[] or uint8_t[] in C++. Objects like std::wstring_t that have a specific encoding (like UTF-8) assigned to them are no byte buffers.

Use this tag only if you're having specific problems in relation with byte buffers. Do not use this tag if there is no indication that the byte buffer you are using has any relation to the problem you're asking about.

919 questions
18
votes
1 answer

Manipulation of ByteBuffer from JNI

I need to pass a (direct) ByteBuffer to native functions that will read/write from/into the buffer. Once these operations are completed, I would like to access the ByteBuffer from Java code using the regular functions; in particular, limit() and…
gonzus
  • 181
  • 1
  • 1
  • 3
17
votes
3 answers

java.nio.BufferUnderflowException while converting byte array to double

I need to convert a bytearray to double. I am using double dvalue = ByteBuffer.wrap(value).getDouble(); But at the runtime I am getting BufferUnderflowException exception Exception in thread "main" java.nio.BufferUnderflowException at…
15
votes
5 answers

Are Java DirectByteBuffer wrappers garbage collected?

I understand that when a directbytebuffer is allocated, its not subject to garbage collection, but what I'm wondering is if the wrapping object is garbage collected. For example, if I allocated a new DirectByteBuffer dbb, and then duplicated(shallow…
Li Pi
  • 486
  • 5
  • 10
15
votes
1 answer

Difference between ByteBuffer.allocateDirect() and MappedByteBuffer.load()

I was trying to implement a sort of shared cache between two or more JVMs by memory mapping a particular file using MappedByteBuffer. From the specifications I see that when we use MappedByteBuffer.load() it should load the data into a direct…
sim
  • 163
  • 1
  • 2
  • 7
15
votes
4 answers

Fast erase (not clear) a ByteBuffer in Java

I am trying to "clean up" a ByteBuffer to be all zero bytes (all 0x00). I tried to loop over all positions in the buffer and set them to 0x00, but the efficiency is bad. Is there any better way to quickly clear a ByteBuffer - similar to what…
asksw0rder
  • 1,066
  • 1
  • 12
  • 19
14
votes
1 answer

How to use ByteBuffer in the MediaCodec context in android

So far I am able to setup a MediaCodec to encode a video stream. The aim is to save my user generated artwork into a video file. I use android Bitmap objects of the user artwork to push frames into the stream. See the code snippet I use at the…
Nar Gar
  • 2,591
  • 2
  • 25
  • 28
14
votes
2 answers

Options to make Java's ByteBuffer thread safe

What options do I have to make a ByteBuffer thread safe? It is known that it is not thread safe as it safes position, limit and some(/all?) methods depend on this internal state. For my purposes it will be sufficient if multiple read-threads are…
Karussell
  • 17,085
  • 16
  • 97
  • 197
13
votes
1 answer

How to append Protocol Buffers in Swift?

I have a protobuf v2 in Swift and I'm trying to append it to another protobuf. This is what I'm trying: let attachment = getAttachment(id: 987) //From cloud database var protosData = NSMutableData(data: attachment) items.forEach { //Some struct…
TruMan1
  • 33,665
  • 59
  • 184
  • 335
13
votes
1 answer

How to expose raw byte buffers with Boost::Python?

I've got third party C++ library in which some class methods use raw byte buffers. I'm not quite sure how to deal in Boost::Python with it. C++ library header is something like: class CSomeClass { public: int load( unsigned char *&…
vartec
  • 131,205
  • 36
  • 218
  • 244
13
votes
7 answers

How to convert a String array to a Byte array? (java)

I have a one dimensional String array that I want to convert into a one dimensional byte array. How do I do this? Does this require ByteBuffer? How can I do this? (The strings can be any length, just want to know how to go about doing such an act.…
Code Doggo
  • 2,146
  • 6
  • 33
  • 58
12
votes
2 answers

compare ByteBuffer contents?

What's the easiest way in Java to compare the contents of two ByteBuffers to check for equality?
Jason S
  • 184,598
  • 164
  • 608
  • 970
12
votes
2 answers

Extract String from ReadOnly java.nio.ByteBuffer

How do you extract a String from a read-only ByteBuffer? I can't use the ByteBuffer.array() method because it throws a ReadOnlyException. Do I have to use ByteBuffer.get(arr[]) and copy it out to read the data and create a String? Seems wasteful to…
Verhogen
  • 27,221
  • 34
  • 90
  • 109
12
votes
2 answers

Compare Direct and Non-Direct ByteBuffer get/put operations

Is get/put from a non-direct bytebuffer faster than get/put from direct bytebuffer ? If I have to read / write from direct bytebuffer , is it better to first read /write in to a thread local byte array and then update ( for writes ) the direct…
user882659
  • 161
  • 1
  • 9
11
votes
5 answers

how can I subclass ByteBuffer?

So the Java NIO architects didn't make a ByteBuffer interface, but rather a ByteBuffer class, which isn't a final class, but it has no package-public constructors, and therefore it can't be subclassed outside of its package. Phooey. :P I have a…
Jason S
  • 184,598
  • 164
  • 608
  • 970
11
votes
4 answers

ByteBuffer not releasing memory

On Android, a direct ByteBuffer does not ever seem to release its memory, not even when calling System.gc(). Example: doing Log.v("?", Long.toString(Debug.getNativeHeapAllocatedSize())); ByteBuffer buffer =…
Kasper Peeters
  • 1,580
  • 2
  • 18
  • 37
1 2
3
61 62