Jeff Flinn wrote:
"JustSomeGuy" <No***@ucalgary.ca> wrote in message
news:40**************@ucalgary.ca... I have an stl list that grows to be too huge to maintain effectivly in
memory.
There are elements within the list that could be stored on disk until
accessed.
However I don't want to expose this to the application class.
How can I extent the stl list to write some elements to disk when they
are put in the list
and read them from disk when they are read from the list.
All the list methods need to still work like iterators and sort
methods....
See GoF Proxy Pattern.
Jeff F
Sorry I don't have this book... Nor do I know what you mean... But thanks
I'll try to figure out what you are trying to tell me...
"Design Patterns" by Gamma, Helm, Johnson, Vlissides ( the Gang of Four )
I assume you are specifying a list because you need to do some constant time
insertions at arbitrary locations within the list. If not provide some more
detail, and there may be better approaches. You wouldn't extend std::list,
in
that you wouldn't derive from it. You don't provide much detail. But if it
is
costly to construct each item, then you would create a lightweight proxy
class
that represents each item.
class proxy
{
some_handle mHdl;
bool mLoaded;
void LoadIt(){ if( !mLoaded ){ /* load from disk using the handle
data*/ } }
public:
proxy( some_hdl aHdl ):mHdl(aHdl),mLoaded(false){}
void some_method(){ LoadIt(); /* some other actions */ }
}
typedef std::list<proxy> tProxyList;
some_func()
{
tProxyList lPs;
lPs.push_back( 1 );
lPs.push_back( 2 );
...
lPs.back().some_method(); // only this one is actually loaded
}
Jeff F