Redefining new

N

notme

I have code with lots of "new int..." etc..
I'd like to replace every instance with "new(allocInfo) int" (that is, using
placement new)

I tried doing:
#define new (new(allocInfo))

but that doesn't work... any hints?
Thanks!
 
P

Phlip

notme said:
I have code with lots of "new int..." etc..
Why?

I'd like to replace every instance with "new(allocInfo) int" (that is, using
placement new)

I tried doing:
#define new (new(allocInfo))

If you actually need a "new int...", why does it appear in so many places
that it's hard to upgrade?

Are all those "new int..." things appearing in similar code that could be
refactored together?

More important: Can't those objects appear on your stack? Why the heap
abuse?
 
N

notme

I have code with lots of "new int..." etc..

Well, it was just an example. You should take the "etc" as "new Object",
that
is, allocating (some of the quite big) objects in the heap.
If you actually need a "new int...", why does it appear in so many places
that it's hard to upgrade?

Don't know, but that's not the point (the code isn't mine, I'm just making a
port)
Are all those "new int..." things appearing in similar code that could be
refactored together?

Unfortunately not.
More important: Can't those objects appear on your stack? Why the heap
abuse?

So, is it possible?

Regards,
David.-
 
P

Phlip

notme said:
So, is it possible?

MFC modules always say this:

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

Hence, DEBUG_NEW looks a little bit like this:

#define DEBUG_NEW new(THIS_FILE, __LINE__)



Note that redefining a keyword is legal, after you #include your C++
standard library headers...
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top