Answer the question
In order to leave comments, you need to log in
Structures in JAVA - what am I doing wrong?
Everyone knows that Java does not support structures and will not. To avoid misunderstandings, what I mean by structures: in fact, this is a lightweight class that has only fields that lie in a certain order and the structure has a size equal to the sum of the sizes of the fields. So, for example, this structure:
struct MyStruct {
int field1;
int field2;
long field3;
byte field4;
}
It takes 17 bytes in memory, no more, no less + a link to it. In Java, classes take longer, that's known. Answer the question
In order to leave comments, you need to log in
I highly recommend watching the recording of the JUG.ru meeting with Roman Elizarov - Millions of quotes per second in pure Java . The main topic of the lecture is just "structures" in Java. There are answers to all the questions that you voiced in this thread, and much more.
On the subject: the allocation itself is definitely not something that should be “optimized” under the current Hotspot.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question