473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Regarding overloading new and delete operators

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 = 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 ?

Feb 1 '07 #1
2 1419
On Feb 1, 6:34 am, rohits...@gmail.com 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 = 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 = 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öm

Feb 1 '07 #2
On Feb 1, 5:16 pm, "Erik Wikström" <eri...@student.chalmers.sewrote:
On Feb 1, 6:34 am, rohits...@gmail.com 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 = 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 = 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öm- Hide quoted text -

- Show quoted text -
It seems to be working.
Thanks alot Erik.

Feb 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am...
12
by: ravinderthakur | last post by:
hi experts, i have few questions regarding the delete operator in c++. why does c++ have to operators for deleting memeory viz delete and delete. why cannnot delete be used insted of...
3
by: Lighter | last post by:
The C++ Standard Doesn't Permit Overloading new and delete? In the 13.5 of The C++ standard (ISO/IEC 14882, 1998), I cannot find the specification on overloading the operators new and delete;...
5
by: Jerry Fleming | last post by:
As I am newbie to C++, I am confused by the overloading issues. Everyone says that the four operators can only be overloaded with class member functions instead of global (friend) functions: (), ,...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.