• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Overheads using short datatype

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
I have a requirement for declaring an int constant. The value of constant is less than 10. I am using short datatype for storing this constant value.
Could you please tell me if there are some performance overheads of using short over int datatype.
Thanks & regards,
Rakesh Nagar
------------------
 
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This seems like a good question for the knowledgable folks in the Performance forum, so I'm moving this question there.
Sean
 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might find the following discussion relevant:
http://www.javaranch.com/ubb/Forum15/HTML/000098.html

--Mark
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rakesh nagar:
Hi there,
I have a requirement for declaring an int constant. The value of constant is less than 10. I am using short datatype for storing this constant value.
Could you please tell me if there are some performance overheads of using short over int datatype.
Thanks & regards,
Rakesh Nagar



I would say yes, short will be slower. I think it is represented as an int in memory. But its still a short to the code. If you do any operations on it the result will be an int, which you will have to cast back to short. shorts basically require lots of casting, and I prefer not to use them in RAM, but they are preferred in storage if possible.
 
reply
    Bookmark Topic Watch Topic
  • New Topic