• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I do this..?

 
mohamed zafer
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello There,
I have a hashtable (say H) which is accessed by other objects. The access to H is read only.
At a later point of execution,I change the data stored in H . So any NEW object accessing H will get the latest data, the same applies to any object already refering H. How can I impose that any object already refering H ,should get access only to the old data, and not the changed data.
One way to do this is, instead of sharing H, each object which want to access H, is given a new cloned copy of H, so even if the data in H is changed, they can still get access to old data.
But if the size of H is considerably high, then creating a copy everytime will involve huge memory.
Any alternative way to achieve this..
Mohamed Zafer
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a chain of hashtables. Every time you change the data, you create a new hashtable with the changed data and a reference to the previous one. If the new hashtable doesn't find an object among its own data, it had to delegate the request to the previous one.
This way objects with old references wouldn't see the new data and you wouldn't have to duplicate the old data.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic