473,406 Members | 2,867 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,406 software developers and data experts.

Can new operator be used as macro?

For some debugging purpose I want to use overloaded new instead of
existing MyAlloc() in a huge code base.
But below macro doesnt work.
Is there any way to pass "size" to overloaded new ?
#define MyAlloc(size) new(size, WORK_HEAD )

overloaded new code is :
void* operator new(size_t sz, int headType) {
..
..
..
}

Mar 2 '07 #1
2 2374
JeanDean wrote:
For some debugging purpose I want to use overloaded new instead of
existing MyAlloc() in a huge code base.
But below macro doesnt work.
Is there any way to pass "size" to overloaded new ?
#define MyAlloc(size) new(size, WORK_HEAD )

overloaded new code is :
void* operator new(size_t sz, int headType) {
.
.
.
}
Use operator new (which is a different thing from the new operator), but
why use a macro?

inline void* MyAlloc(size_t size)
{
return ::operator new(size, WORK_HEAD);
}

Look's OK to me, unless I'm misunderstanding you.

john
Mar 2 '07 #2
On Mar 2, 4:59 pm, John Harrison <john_androni...@hotmail.comwrote:
JeanDean wrote:
For some debugging purpose I want to use overloaded new instead of
existing MyAlloc() in a huge code base.
But below macro doesnt work.
Is there any way to pass "size" to overloaded new ?
#define MyAlloc(size) new(size, WORK_HEAD )
overloaded new code is :
void* operator new(size_t sz, int headType) {
.
.
.
}

Use operator new (which is a different thing from the new operator), but
why use a macro?

inline void* MyAlloc(size_t size)
{
return ::operator new(size, WORK_HEAD);

}

Look's OK to me, unless I'm misunderstanding you.

john
Thanks a lot for the suggestion

Mar 2 '07 #3

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

Similar topics

11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
8
by: mrstephengross | last post by:
I'm using gcc 3.3.1 to compile the following code (below). I've written a macro to simplify writing operators. The macro uses the '##' operator to paste together 'operator' and the name of the...
11
by: Shawn Odekirk | last post by:
Some code I have inherited contains a macro like the following: #define setState(state, newstate) \ (state >= newstate) ? \ (fprintf(stderr, "Illegal...
2
by: grid | last post by:
Hi, I need some clarifications on how the comma operator is used to return values from function like macros.I saw a typical implementation as : #define sigfillset(ptr) ( *(ptr) &= ~(sigset_t)0 ,...
3
by: Wessi | last post by:
Hi, token pasting means, that normally whitespaces and comments are deleted before and after the ## operator. I want the preprocessor to hold an existing whitespace while replacing the argument...
1
by: Peter | last post by:
Hi in Clipper and VisualObjects is a Macro Operator available. This opeartor evaluate Code stored in a String by the runtime-system. e.g .... cTest as string cTest := "2+3"
6
by: pedroalves | last post by:
Hi all, This is not a question about how to #define COMMA , Please keep reading. Recently in binutils, we introduced a macro like this: #define STRING_COMMA_LEN(STR) \ (STR), ((STR) ?...
16
by: mail2sandeepnl | last post by:
hi all what are the applications / examples that requires concatenation of 2 pre-processor variables. i.e applications of " ## " operators in C/C++ i think its only use is in Compiler...
13
by: Tristan Wibberley | last post by:
Hi I've got implementing overloaded operator new and delete pretty much down. Just got to meet the alignment requirements of the class on which the operator is overloaded. But how does one...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.