Skip to content

Leverage NIO ByteBuffers in TileDB Java [ch2662] #180

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

Conversation

gsvic
Copy link
Contributor

@gsvic gsvic commented Jul 6, 2020

No description provided.

@gsvic gsvic requested a review from Shelnutt2 July 6, 2020 17:56
@gsvic gsvic force-pushed the victorgiannakouris/ch2662/leverage-nio-bytebuffers-in-tiledb-java branch 4 times, most recently from 5da3465 to bdafbe5 Compare July 7, 2020 14:16
@gsvic gsvic force-pushed the victorgiannakouris/ch2662/leverage-nio-bytebuffers-in-tiledb-java branch from bdafbe5 to 0570207 Compare July 9, 2020 11:32
@gsvic gsvic merged commit 5e1ccc1 into master Jul 9, 2020
@gsvic gsvic deleted the victorgiannakouris/ch2662/leverage-nio-bytebuffers-in-tiledb-java branch July 9, 2020 12:17
a1.order(ByteOrder.nativeOrder());
a2.order(ByteOrder.nativeOrder());

for (int i = 0; i < floatArr.length; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the String, the following should work:

byte[] stringAsBytes = str.getBytes(StandardCharsets.UTF_8);
ByteBuffer a1 = ByteBuffer.allocateDirect(stringAsBytes.length);
a1.put(stringAsBytes);

and for the float[]:

a2.asFloatBuffer().put(floatArr);

You can always "upcasting" a ByteBuffer in this fashion to get a view of the original buffer in the type of your choosing. Very useful to avoid walking the buffer in a methodwise fashion.

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

Successfully merging this pull request may close these issues.

3 participants