Jump to content
  • Advertisement
Sign in to follow this  
NFalcon

macro new global?

This topic is 4132 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I currently have something like this set up: void * operator new (size_t size, const char *file, int line) { return _malloc(file, line, size); } void operator delete (void *p) { _free("unknown file", 0, p); } #define NEW new (__FILE__, __LINE__) #define new NEW It works fine and calls my new for the allocations within the file I am including my overloaded new and delete file in, but when something is allocated out side of that file, it just calls C++'s operator new. Is there anyway I can make this global for all the files in a project?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by NFalcon
Is there anyway I can make this global for all the files in a project?


Put the macro in the header that prototypes those functions?

Share this post


Link to post
Share on other sites
The macro is in the header file with the prototyped functions. Its actually all one .h file with those functions and macro as global, but it doesn't work throughout the entire project like I had hoped. The only thing I can really think of is using pre-compiled headers and include the .h in my stdafx, but I was hoping I wouldn't have to do that. =(

Share this post


Link to post
Share on other sites
Your global new macros will not be called if the files/functions cannot see it's definition. You have to make sure that all files in your project have the correct .h file included and it is included before all the other includes in your project.

It might be a case that you are including something after this that undefines/redefines new again, meaning your code is not being used, but if it's happening in all other files, than chances are your include order is incorrect.

Also, putting this in a pre-compiled header wouldn't be a bad thing since the header file (if it contains only the new/delete macros) won't change, which is one of the recommended features of a PCH. Remeber you don't have to create pre-compiled headers using MS's stdafx system. :)

Spree

Share this post


Link to post
Share on other sites
I have tried implementing PCH for the project and for some reason I get a list of compiler errors saying that certain functions and variables are already defined in stdafx.obj. I have tried placing #ifndef around my CMemPool class and function definitions but it doesn't seem to work.
How do I get around accidentally redefining my CMemPool's information?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!