References in Java
A reference is essentially an object’s memory address
Variables containing address are often termed ‘pointers’
A pointer can be thought of as a low-level reference
‘Pointer arithmetic’ – e.g. add offsets, indexing
A pointer is just another type, like an int or a float
Everything stored in memory, pointers included, has an
address: another pointer can even point to it
Arrays
Usually a block of consecutive elements in memory
All same size (s bytes); same offset from one to the next
The i th element is at offset i × s bytes from beginning
Looking up an element of the array is termed ‘indexing’
Assembly equivalent of an int[] in Java would be. . .
a consecutive block of word-sized signed integers
represented by its starting address and length
static data: Contents may change, but size and location doesn’t
In Java, "hello" + "world" contatenates two strings, But neither of the original strings are modified. Instead a new string is created on the heap
The heap is a much larger pool of memory than the stack
Java allocates storage on the heap with the new keyword
All Java objects live on the heap; only primitive types –ints, floats, doubles and references – on the stack
Storage allocated on the heap persist across procedures. Caller can’t access stack storage//-----?????????????
Monday, 14 May 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment