473,549 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Redefining new

I have code with lots of "new int..." etc..
I'd like to replace every instance with "new(allocI nfo) 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
3 1934
notme wrote:
I have code with lots of "new int..." etc..
Why?
I'd like to replace every instance with "new(allocI nfo) 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
>> 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(allocI nfo) 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2358
by: Robert Ferrell | last post by:
I have a question about assigning __call__ to an instance to make that instance callable. I know there has been quite a bit of discussion about this, and I've read all I can find, but I'm still confused. I'd like to have a factory class that takes a string argument and returns the appropriate factory method based on that string. I'd like...
5
6245
by: uli | last post by:
Hi all! I'm posting to both newsgroups, because it's actually a C++ problem but could be that some of you using Matlab-&-MEX-&-C++ was struggling with the same problem. I'm trying to rewrite some Matlab routines in C++ for reusing them identically in Matlab and some other simulation tools. For computational algebra I want to use the Matrix...
1
2363
by: Xiangliang Meng | last post by:
Hi, all. When reading C++ books, I'm alway confused by those terms "redefining functions", "overloading functions" and "overriding functions". Please give me some comments on those terms. Thanks. If giving more strategy hehind them, more helpful. Best Regards,
7
4546
by: bberu | last post by:
Hi, I know it is possible to refine operators (like +, -, * or /) on classes. But is it possible on simple types ? ex : If I have a type like : typedef int vector is it possible to redefine a + operator on the vetor type ? Thanks !
0
1456
by: Imre | last post by:
I'm planning to create a macro-based property system (reflection, automatic serializing for properties, that kind of stuff). The system would involve writing some PROPERTY(propName) macros between a BEGIN_CLASS(ThisClass) and an END_CLASS() macro. The PROPERTY macros should somehow know ThisClass, and that's where it start to get tricky. ...
2
1600
by: Bob | last post by:
How can I reuse an object that is already defined. I want to delete some files using the FileInfo class and the "name" is a read only property so I can't set the name as I want to. I don't want to delete all the files only a few of them in different Directories For example this gives me an error. Is there a way to reset "FI" in this case......
3
1244
by: Mythran | last post by:
man, it's been quite a long time since I was developing in C/C++ (GNU Linux on RedHat 6.2 was last time I did)... Anywho, I can't remember how to re-define/re-dimension an array. Say I have an array of 30 characters...the first character is a space...I want to remove this space... OR
4
3886
by: allan.mcrae | last post by:
As part of a very simple memory leak detector, I am trying to store the value of __FILE__ in a char*. Since gcc4.2 I get the following warning... warning: deprecated conversion from string constant to 'char*' object. The macro of delete assigns this to a global char* which is used to track where deletions were made. Something like: ...
4
1864
by: Belebele | last post by:
The following code fails to compile. My intention is to provide different definitions for a nested class for a class template partial specialization. Here it is: template <typename , int class Outer { public: class Inner; };
0
7541
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7734
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5385
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5107
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1960
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1074
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
781
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.