sura2k
sura2k

Reputation: 7517

Memory Address of Array - Java

Does anybody know to get the memory addresses of an array indexes? (like in c)

Upvotes: 2

Views: 4260

Answers (2)

templatetypedef
templatetypedef

Reputation: 373402

There is no programmer-realizable notion of an "address" in Java. In a language like C or C++, objects' identities are equated with their address - two objects are the same object if they live in the same memory location. In Java, this notion of identity is decoupled from the object's address. This allows some optimizations that are not possible in C++. For example, the garbage collector could, in theory, move objects around in memory to avoid fragmentation, so long as it modifies references so they point to the right location. Because memory addresses can't be accessed directly by the programmer, this operation is permissible. In C++, it wouldn't work, because the compiler couldn't tell if a particular bit pattern in memory was some sort of encoded pointer.

Upvotes: 5

Programmdude
Programmdude

Reputation: 541

You can't. Java doesn't have direct memory access.

Upvotes: 1

Related Questions