Override operator new. Class-Based or Global Overridden

E

Ed

Hi, guys,
When I trying to control the memory allocation to a module, which way
is best for me, Class-Based or Global Overridden?

I plan to make use of TBB allocator to manage the memory allocation.
Two ways.
1 Make all the resources inherited from new/delete operator function.
2 Create a global new/delete operator function under module namespace.

I prefer the second way, since the first way can not cover the
primitive type, like int array, float array, string, etc.

What do you think?

Thanks.
 
Z

ZikO

Ed said:
Hi, guys,
When I trying to control the memory allocation to a module, which way
is best for me, Class-Based or Global Overridden?

The problem with global redefinition of operator new is that you will
change behaviour of new for every I mean every single standard library
of C++ let's say iostream's cout and cin will also be working according
to your new "new". If it's your intention, yes, use that global
definition. however, if you think that new should work normally for the
rest besides your class, dont make them in global scope, use them as
member functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top