The vast majority of a DirectByteBuffer – if large enough – is allocated off the Java Heap. But a portion of it will still be on the heap, even if its very small.
How many bytes does a DirectByteBuffer of any size take up on the heap?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is obviously implementation defined, as the Java spec doesn’t make any guarantees about this stuff. For a modern hotspot VM: 2 words overhead per object (and to be exact at least 1 word for variables even if the object doesn’t have any). Now you basically have to count. Every object has to be 8byte aligned.
As an example lets look at DirectByteBuffer: We see that it stores one object (1 word). Now if it shares this object with something else you may or may not want to count it. If you count it you’ll have to find out what object is stored and compute its size as well (therefore depends on your exact codepath). Since DirectByteBuffer extends a class you’ll have to add that size as well to it.
Yep that’s quite some work and I sure as hell won’t do it for you 😉 But it’s quite simple. I count at least 3 references and 29byte primitives..