Suppose I have a very large std::map< unsigned int, Foo > FooDBone that contains Fooobjects in memory retrieved by their identifier. Now there may be more objects Foothan there is memory available for storing them. Therefore, I would like to have the following construction:
std::map< unsigned int, Foo > FooDB
Foo
FooDB
I would like to reserve some memory for FooDB, and I can’t say how many objects Foocan be stored in it, since they differ in size.
Any ideas on how to implement this?
EDIT
My main problem: how can I determine the size std::mapin memory? Of course, all heap objects stored in it included. How to find out when insufficient memory is reached?
std::map
, , sizeof(). , sizeof() , Foo . , Foo, , , Foo . Foo, , , .
, // , , , . , , , , , "". , , , , -, .
, Foo . , . , , , .
.
Foo FooDB , .
, .
/ , .
, , .
:
typedef shared_ptr<Foo> PFoo; class Foo { ... list<PFoo>::iterator age; }; typedef map< unsigned int, PFoo > FooDB; FooDB foodb; list<PFoo> ages; void LoadFoo(PFoo foo) { ages.push_front(foo); } void ReadFoo(PFoo foo) { ... ages.erase(foo->age); ages.push_front(foo); } void MakeSpace() { PFoo foo = ages.back(); ages.pop_back(); DeleteFoo(foo); }