Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Need help extending stl list. (http://www.velocityreviews.com/forums/t283383-need-help-extending-stl-list.html)

JustSomeGuy 05-28-2004 05:51 PM

Need help extending stl list.
 
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.





Jeff Flinn 05-28-2004 06:03 PM

Re: Need help extending stl list.
 

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



JustSomeGuy 05-28-2004 07:23 PM

Re: Need help extending stl list.
 
Jeff Flinn wrote:

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



Jeff Flinn 05-28-2004 08:25 PM

Re: Need help extending stl list.
 

> Jeff Flinn wrote:
>
> > "JustSomeGuy" <NoOne@ucalgary.ca> wrote in message
> > news:40B77C3D.BAE49CA@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



John Harrison 05-28-2004 08:31 PM

Re: Need help extending stl list.
 

"JustSomeGuy" <NoOne@ucalgary.ca> wrote in message
news:40B791CC.8FED8BEC@ucalgary.ca...
> Jeff Flinn wrote:
>
> > "JustSomeGuy" <NoOne@ucalgary.ca> wrote in message
> > news:40B77C3D.BAE49CA@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



JustSomeGuy 05-30-2004 04:45 PM

Re: Need help extending stl list.
 

"Jeff Flinn" <NONONE@nowhere.com> wrote in message
news:c9877b$r7s$1@bluegill.adi.com...
>
> > Jeff Flinn wrote:
> >
> > > "JustSomeGuy" <NoOne@ucalgary.ca> wrote in message
> > > news:40B77C3D.BAE49CA@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?






JustSomeGuy 06-01-2004 05:29 PM

Re: Need help extending stl list.
 
John Harrison wrote:

> "JustSomeGuy" <NoOne@ucalgary.ca> wrote in message
> news:40B791CC.8FED8BEC@ucalgary.ca...
> > Jeff Flinn wrote:
> >
> > > "JustSomeGuy" <NoOne@ucalgary.ca> wrote in message
> > > news:40B77C3D.BAE49CA@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?





All times are GMT. The time now is 02:52 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.