• Post Reply Bookmark Topic Watch Topic
  • New Topic

Memory question;  RSS feed

 
Nev Mehta
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I had a some general questions about hashtables.

Q. Say in a hashtable we have

a -> some array A
b -> some array A

Say now i execute;
B = table.get('b')
B = some array C
table.put('c',C); or table.put('c',B);

Will the hashtable look like this now?

a -> some array C
b -> some array C
c -> some array C

Q. If i have a few keys that map to the same array; will the hashtable store references or copy the whole array as the value?

so for e.,g.
a - > some array A
b - > some array A
c - > some array A

Will array A be stored as just one copy (or 3 copies) in memory;

Thanks'
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the a, b or c keys point to one and the same object (which in your case is true) then there is only 1 copy on the heap, since a, b, c only hold the reference pointer id ...
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The hash table will store only references to the arrays. However, if you call put('c', C), that will only change the value mapped for 'c'. 'a' and 'b' still have the old array as their values.

Now, in the following, you will change all arrays A:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!