2

I read that byte data type takes up smaller amount of memory compared to integer data type in JVM. But, I am curious whether the statement above also works for Android Dalvik VM. Is it correct that using byte instead of integer in Android will improve efficiency ?

FYI, currently i am using an array which stores hundred-thousands of int, but the integer only fluctuates between 0-10. So I'm considering changing it to byte if it can improve the performance of my program.

My apologies if my question sounds stupid since I'm new to Java.

Thanks in advance :)

2
  • That's a hard one to answer because it will likely be hardware dependent. It's all about how the hardware will handle this kind of data. Generally speaking, it's more likely to be more efficient than int, but I'm not quite sure you can say it's a sure thing that it will be efficient. Part of it is related to how bytes get aligned in the physical ram. Is it aligned to single bytes? pairs of bytes? four bytes? Hard to say. Commented Aug 12, 2012 at 16:21
  • It may, yes. If there is a little bit of overhead due to using Byte instead of Int I would imagine it will be negligible. If your priority is to use less memory, then go ahead and use Byte. If you don't care so much about memory, you might as well stick to Int. Commented Aug 13, 2012 at 14:23

2 Answers 2

1

Android Developer Reference:

You can go through the above documents for byte and integer. From the max and min values given in the links above, it seems byte takes up 1 byte and int takes up 4 bytes of memory. byte should reduce memory usage for sure.

Sign up to request clarification or add additional context in comments.

Comments

0

Adding to the answers above, I would like to point to this question for an additional reading:

Size of a byte in memory - Java

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.