Writing double[] with java.nio

D

Derek Waldron

Hi,

I have a very large double[] that I want to send across a channel in
java.nio. Is there a better way to do this than the following?

double[] myarray = new double[very large];

ByteBuffer bb = ByteBuffer.allocate(myarray.length*8);
DoubleBuffer db = bb.asDoubleBuffer;
db.put(myarray);

channel.write(bb);

It seems to me that there should be a more direct way by using
DoubleBuffer directly, for example:

DoubleBuffer db = DoubleBuffer.wrap(myarray);

but write only accepts ByteBuffer and so channel.write(db) won't work.

Ideally, I would like to avoid the first piece of code because it
requires copying the entire array.

Any suggestions?

Thanks!

Derek
 
A

Andrei Kouznetsov

I have a very large double[] that I want to send across a channel in
java.nio. Is there a better way to do this than the following?

double[] myarray = new double[very large];

you can use smaller Buffer and transfer your data piecewise in a loop.
You can also use Unified I/O to transfer data between arrays with different
(primitive) types.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top