Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Instance variable memory conumption in java?  RSS feed

 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a question about Instance variable memory conumption in java?

Do instance variables always consume 4 bytes? in other words, using bytes,shorts,and Boolean types do not save any memory than using an int?

Thank you.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Java In General (Beginner) forum.

This forum is for J2ME for mobile devices.

Mark
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Some are smaller than four bytes, some larger, some undefined. In generael, the size of the variable should be of little concern in terms of memory. You use a short when a short is appropriate and an int when an int is appropriate. Using one or the other due to memory is probably a bad idea unless you have reason to believe that's an issue.
 
Paul Clapham
Sheriff
Posts: 22472
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ken Blair:
Using one or the other due to memory is probably a bad idea unless you have reason to believe that's an issue.
Agree entirely, but in the J2ME forum (where this was moved from) you do have more reason to believe that.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!