Best practice for getting datatype size(sizeof) in Java

Viewed 68840

I want store a list of doubles and ints to a ByteBuffer, which asks for a size to allocate. I'd like to write something like C's syntax

int size=numDouble*sizeof(double)+numInt*sizeof(int);

But there is no sizeof in Java. What is the best practice to calculate the size in byte? Should I hardcode it?

7 Answers

Automated and abstract solution is to write the sample to DataOutput and see the resulted size.

Related