Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

Issue with DirectByteBuffers

Thread view: 
gkrasnow@gmail.com - 26 Mar 2008 19:10 GMT
I am working on a system where we continually jump between native code
and java code.  I have a place where I use NewDirectByteBuffer in the
native code to create a data buffer I can use to pass data back and
forth from java.

I am finding that under certain circumstances I call
NewDirectByteBuffer() with an address and size.  I can then call
GetDirectBufferCapacity() and see that the size is indeed the size I
used in my NewDirectByteBuffer() call.  However, when I then pass the
jobject across the JNI boundary back into java and I look at the
capacity() on the java.nio.ByteBuffer, the capacity reported is
smaller then what I requested.  Has anyone else run into this issue?
Thanks.

- Greg
Zig - 27 Mar 2008 21:58 GMT
> I am working on a system where we continually jump between native code
> and java code.  I have a place where I use NewDirectByteBuffer in the
[quoted text clipped - 11 lines]
>
> - Greg

Can you post a SSCCE?

What VM, platform & architecture are you using? Is your buffer being  
allocated within the VM's process space, or by some other memory allocator?

How much smaller is the VM capacity than native capacity? If it's 8 bytes  
or less, you may have an alignment issue in your pointer arithmetic.

If you are using view buffers around your ByteBuffer, you could still be  
doing something wierd with alignments.

Also, inside the VM, buffer capacities are limited to 2^31-1. I think JNI  
allows you to go bigger, as you may be able to do fancy things like create  
a ByteBuffer up to 2^33-1 bytes and promote it to an IntBuffer before  
handing it back to the VM. Though, I have no idea how well VMs support  
those kinds of promotions, so you should probably be staying under 2 GB.

HTH,

-Zig


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.