By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

Redefining new

P: n/a
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!
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
notme wrote:
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?

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #2

P: n/a
>> I have code with lots of "new int..." etc..

Why?
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.
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?


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.-
Jul 23 '05 #3

P: n/a
notme wrote:
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...
--
Phlip
http://industrialxp.org/community/bi...UserInterfaces

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.