On Feb 1, 5:16 pm, "Erik Wikstr=F6m" <eri...@student.chalmers.se> wrote:
On Feb 1, 6:34 am,
wrote:
To optimize the memory usage , I am using a huge block of memory for
my system and
then dividing the initial chunk in to 4 pools.
I have overloaded new and delete such that memory from a particular
pool can be taken and
freed .
As far as possible memory can be taken from particular pool and memory
is freed (comlete pool as whole ) when pool is completely used.
By overlaoding new and delete , I can pass the information about a
particular pool say:
CMyClass* myClass =3D new (POOL_1) CMyClass;
...
delete(POOL_1) s;
But the problem is while using the abtsract containers say vector, I
am not able the POOL related information till new and delete which are
used inside allocator.
I am using the userdefined allocator :
vector<int,MySpace::MyAllocator<int> > v;
so that overloaded version of new and delete are called , but it is
not possible to pass the POOL related information in case of
containers .
Any suggestions ?
I've never tried this myself so I don't know if it's possible, but
couldn't you add the pool as a parameter to the allocator?
template<class T, int P =3D 0>
class MyAllocator
{
const int pool_;
public:
MyAllocator() : pool_(P) { /* ... */ }
};
And you could use it something like:
vector<int,MySpace::MyAllocator<int, 2> > v;
or, if the default pool is ok then just
vector<int,MySpace::MyAllocator<int> > v;
--
Erik Wikstr=F6m- Hide quoted text -
- Show quoted text -
It seems to be working.
Thanks alot Erik.
.