By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Need help extending stl list.

P: n/a
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....

TIA.
B.


Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

"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
Jul 22 '05 #2

P: n/a
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...
Jul 22 '05 #3

P: n/a
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
Jul 22 '05 #4

P: n/a

"JustSomeGuy" <No***@ucalgary.ca> wrote in message
news:40***************@ucalgary.ca...
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...


I don't have the book to hand either but I think what Jeff is saying is that
you shouldn't be trying to extend std::list. Instead you should use a
regular list but in that list you should store objects which are proxies for
your real objects.

The real objects maybe on disk, they may be in memory, the proxies will
handle that. But that is where you should be adding the smart behaviour to
your code, in the proxy objects not in the list.

For instance the proxy class could maintain a pool of frequently accessed
objects, those would be stored in memory and the remainder on disk. Some
algorithm could determine when an object counts as frequently accessed and
is added to the pool (and when a less frequently accessed object is removed
from the pool).

john
john
Jul 22 '05 #5

P: n/a

"Jeff Flinn" <NO****@nowhere.com> wrote in message
news:c9**********@bluegill.adi.com...
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


I think you are on the right track and understand my problem.
My problem is that some objects are simply too large to be maintained in
memory
effectivly.. yet the requirements that they be orginized as a list is sound.
I was thinking that over-riding operator= for the class of objects in the
list might
be an easy way to impliment this.. However I guess there is no way to tell
if I actually
need the data or the handle to it. Adding a 'get' method is what I believe
you are suggesting,
but that changes the class interface doesn't it?

Jul 22 '05 #6

P: n/a
John Harrison wrote:
"JustSomeGuy" <No***@ucalgary.ca> wrote in message
news:40***************@ucalgary.ca...
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...


I don't have the book to hand either but I think what Jeff is saying is that
you shouldn't be trying to extend std::list. Instead you should use a
regular list but in that list you should store objects which are proxies for
your real objects.

The real objects maybe on disk, they may be in memory, the proxies will
handle that. But that is where you should be adding the smart behaviour to
your code, in the proxy objects not in the list.

For instance the proxy class could maintain a pool of frequently accessed
objects, those would be stored in memory and the remainder on disk. Some
algorithm could determine when an object counts as frequently accessed and
is added to the pool (and when a less frequently accessed object is removed
from the pool).

john

john


Sorry my design pattern knowlege is slim, I found the uml representation but
I'm not sure
how this helps me.
However if I understand you, then the list contains instances of the Proxy
class not
instances of the actual class. Is that correct?

Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.