aspose file tools*
The moose likes Java in General and the fly likes How can I do this..? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How can I do this..?" Watch "How can I do this..?" New topic
Author

How can I do this..?

mohamed zafer
Ranch Hand

Joined: Nov 03, 2000
Posts: 62
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

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I do this..?