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

Object in Memory  RSS feed

 
Niranjan Prasad
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

This is Niranjan.

I want to know how a Object get stored in Memory?
What i mean to ask is that,we all know that when we initialized a variable
with some value,for examlple
int x=10;
Its 10 in the binanry format is stored,1010 in 32 bits is stored.

In the same way ]
char c='A';
Its ascii value is 67,this ascii values binary format is stored in the memory.

In the same way how does the Object get stored?
Plse explain me this clearly,becoz nobody is explaining this topic clearly.

Niranjan
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly how an object is stored in memory is system-dependent: it may be different for different implementations and versions of the Java virtual machine. So there's no definite description of how an object is exactly laid out in memory.

The chapter RAM Footprint in the Java Platform Performance Guide contains some hints about how to estimate the size of objects (in bytes) in memory.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While the exact details may vary between differnt versions and implementations of the OS, some of the general ideas need to stay the same. For example, you have to use a reference to access an object. A reference is essentially a memory address where the object is stored, although there may be some more complications than that. The memory address that the reference points to should contain the member fields of the object which are in turn stored as you described, if they are primitives, or are other references that point to other objects. There is also some way to indicate where the methods for the object are located.

Again, the exact details of each of these peices is dependent on the JVM and the underlying OS and physical machine. This should give you some idea about some of the general concepts, though.

Layne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!