0

So I'm working on a presentation where I'm trying to show how much more effective a certain program would be if we were to use primitive types instead of wrapper classes, and I'm trying to find the space complexity of different wrappers and how many bytes are being used for which tasks. Can someone help me figure out how many bytes are being used for what in an Integer or a Double?

Thanks!

Daniel Imberman
  • 618
  • 1
  • 5
  • 18
  • How do you define *effective*? – PM 77-1 Jul 29 '14 at 00:14
  • I'm essentially creating a presentation for the business side of my company and I have to explain to them why primitive types are more space efficient than wrapped objects. I want to create a slide that can give a basic idea of what is being put into the extra bytes that we don't need for our purposes. – Daniel Imberman Jul 29 '14 at 00:15
  • Unless you're dealing with embedded systems where you need to count each byte, your issue is immaterial. – PM 77-1 Jul 29 '14 at 00:17
  • I'm dealing with big data where tens of millions of rows can definitely add up when you're saving 4-8 bytes each value. I've already done testing and the data structure I've built cuts the space requirement in half. – Daniel Imberman Jul 29 '14 at 00:19
  • see http://stackoverflow.com/questions/52353/in-java-what-is-the-best-way-to-determine-the-size-of-an-object – vandale Jul 29 '14 at 00:32
  • found it :) http://stackoverflow.com/questions/8419860/integer-vs-int-with-regard-to-memory – Daniel Imberman Jul 29 '14 at 01:14

1 Answers1

0

So the answer to this is that an Integer is 16 bytes. Essentially every object in Java requires 8 bytes of header room for the pointer (reference, etc.), 4 bytes go to the actual int data, and 4 bytes go to "padding"

source: Integer vs int: with regard to memory

Community
  • 1
  • 1
Daniel Imberman
  • 618
  • 1
  • 5
  • 18