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

wrapping new

P: n/a
I am trying to wrap new but am having some problems.

What I want to do is provide my own implementation of "new" Globally not by
class, but within my implementation of new call the regular global new.

So here is the picture.
void* operator new( ... ) // this is my implementation of new
{

// do something

void* operator new(...) // this is the regular new
}
Then when I call new in my program I want my implementation of "new" to be
called which would then call the regular "new".

I have played some games with namespaces but that did not work.

So, I am stuck. Any advice is greatly appreciated.


Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Ian
john smith wrote:
I am trying to wrap new but am having some problems.

What I want to do is provide my own implementation of "new" Globally not by
class, but within my implementation of new call the regular global new.

So here is the picture.
void* operator new( ... ) // this is my implementation of new
{

// do something

void* operator new(...) // this is the regular new
}
Then when I call new in my program I want my implementation of "new" to be
called which would then call the regular "new".

I have played some games with namespaces but that did not work.

So, I am stuck. Any advice is greatly appreciated.


I don't think a user defined new can coexist with the original. You are
replacing the symbol at link time.

Ian

Jul 22 '05 #2

P: n/a

"john smith" <pr**************@charter.net> wrote in message
news:10*************@corp.supernews.com...
I am trying to wrap new but am having some problems.

What I want to do is provide my own implementation of "new" Globally not by class, but within my implementation of new call the regular global new.
[snip]
So, I am stuck. Any advice is greatly appreciated.


You are stuck because the new new is a replacement for the old new not a
wrapper.

Is there any reason you cannot call malloc from inside your new new (and
call free from inside a new delete)?

john
Jul 22 '05 #3

P: n/a
"john smith" <pr**************@charter.net> wrote in message news:<10*************@corp.supernews.com>...
I am trying to wrap new but am having some problems.

What I want to do is provide my own implementation of "new" Globally not by
class, but within my implementation of new call the regular global new.

So here is the picture.
void* operator new( ... ) // this is my implementation of new
{

// do something

void* operator new(...) // this is the regular new
}
Then when I call new in my program I want my implementation of "new" to be
called which would then call the regular "new".

I have played some games with namespaces but that did not work.

So, I am stuck. Any advice is greatly appreciated.


Bruce Eckel's Thinking in C++: Volume 2, edition 2 had some stuff on
this. I personally don't like this book though. Volume 1 was great,
but I just didn't like Volume 2. I found it very difficult and boring,
but I know it does have some information on this.
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.